1

I have created a catalog price rule in Magento adminarea.

For ex. Product A's price is 100 and after applying the catalog price rule, its price becoming 80.

I am trying to fetch the price 80 programmatically but the below code is returning original price only i.e. 100.

$product->getPrice();
$product->getFinalPrice();

3 Answers 3

5

I got the discounted price by below code:

$price = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
1

You can get the discounted price after applying the rule as follows:

   $discounted_price = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product
   ->setStoreId(1)
   ->setCustomerGroupId($grup),
   $product->getPrice()
   );
1
  • The answer is not about magento 2, but about magento 1!
    – PassTeT
    Oct 26, 2021 at 0:11
0

The best way to get Price after a catalog Price rule is applied to it is by

calling

\Magento\CatalogRule\Model\Rule::calcProductPriceRule(Product $product,$price);

You can create object of Rule class in constructor and then call calcProductPriceRule appropriately in your logic to get the currect price when you fail to get it with getFinalPrice func.

3
  • this correct but how to pass product store id ? in my case schedule indexer always pass store id =0. Jan 17, 2023 at 5:15
  • @biplabrout set the store id on $product object before passing it to this function, like this $product->setStoreId($storeId); Jan 17, 2023 at 6:00
  • yes correct but before that we need to get the store ids then set it on product. Jan 19, 2023 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.