9

For example

$_producte = Mage::getModel('catalog/product')->load(2974);
echo $_producte->getFinalPrice();

I can get in frontend when insert to .phtml

BUT I can not get final price (with discount) in admin section or in custom product export file.

Alex
  • 769
  • 1
  • 11
  • 18

2 Answers2

12

Price calculation in Magento is a hot mess. You need to load the frontend event area in order to trigger rule calculation (ref Mage_CatalogRule_Model_Observer::processFrontFinalPrice() configured in Mage_CatalogRule config.xml).

Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
benmarks
  • 23,384
  • 1
  • 62
  • 84
  • What about processAdminFinalPrice? – Kamal Joshi Mar 25 '14 at 14:14
  • What about it? Sounds like a new question to me :-) - perhaps here or over at http://magento.stackexchange.com – benmarks Mar 25 '14 at 15:52
  • Well, that's true but I was surprised why rule calculation triggered by processFrontFinalPrice, Can't it be possible with processAdminFinalPrice? Can ask in separate question.. :) – Kamal Joshi Mar 26 '14 at 06:06
  • FWIW I've learned to be surprised by *nothing* when it comes to Magento price/totals calculation, unfortunately... – benmarks Mar 26 '14 at 10:52
3

I think its not necessary to load the frontend event area part. Often the product is not instanced correctly.

Try:

$product
    ->setStoreId(1) //your store_id here
    ->setCustomerGroupId(1) //your favorite customer group id here
    ->load($productId)

and then:

$product->getFinalPrice()

should give the correct final price.

Otherwise try the solutions given here: https://stackoverflow.com/a/14096072/2787671

ahe_borriglione
  • 467
  • 4
  • 11