Magento 2 – Get Product Final Price in a Block

blocksmagento2product-attribute

How can I get product final_price attribute (affected by a catalog price rule) in a block?
I've tried in this way without success: $this->_productFactory->create()->load($idProd);

I've found price attribute only.

How can I do?

Best Answer

I wanted to get the final_price for the product in /product/view/hero.phtml. So that I could display the stickers based on the discount. Below is what worked for me after spending some time in Magento core:

$finalPriceModel = $_product->getPriceInfo()->getPrice('final_price');

It will return the instance of Magento\Catalog\Pricing\Price\FinalPrice. Which has a method getValue() method defined to return the amount in float. So to just get the amount:

$finalPriceAmt = $_product->getPriceInfo()->getPrice('final_price')->getValue();

I haven't tried this code snippet on list.phtml. But it should work as long as $_product is an instance of Magento\Catalog\Model\Product\Interceptor.

Related Topic