Magento 1.9 – How to Get Product Final Price After Discount Rule Applied

discountmagento-1.9priceshopping-cart-price-rules

I have a custom script located in the root of magento and here i takle all the product prices and create a csv with those values.

I have a problem with the product price when I tried apply a discount rule.
Even in the fronted, it show me the correct price, i mean the price after discount, in my csv i can't take this price.

When I applied a discount rule, in csv i recive the normal price.
This is my code for taking the discounted price:

foreach($collection as $product) {

  //load product by id
   $product = Mage::getModel('catalog/product')->load($product->getId());
   //take tier price 
   $existingTierPrice = $product->tier_price;


    **//get promo_price**
    $promo_price = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());

    if(!$promo_price && $netto_price =='No'){
      $special_price = $_specialPrice = $product->getFinalPrice();
    }elseif($netto_price =='No' && $promo_price){
        $special_price = $promo_price;
    }else{
        $special_price = NULL;
    }

$netto_price it's to No.

Does anyone know why i can't take this discounted price?

Best Answer

//We use to get product price like

$_product->getPrice();

$_product->getFinalPrice();

      //Here you can get the catalog rule applied price like:
            $store_id = Mage::app()->getStore()->getId();
            $discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
                                                      Mage::app()->getLocale()->storeTimeStamp($store_id),
                                                      Mage::app()->getStore($store_id)->getWebsiteId(),
                                                      Mage::getSingleton('customer/session')->getCustomerGroupId(),
                                                                      $_product->getId());


            if ($discountedPrice===false) { // if no rule applied for the product
                $discountedPrice = $_product->getFinalPrice();
            }else{
                $discountedPrice = number_format($discountedPrice,2);
            }
Related Topic