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?
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:It will return the instance of
Magento\Catalog\Pricing\Price\FinalPrice
. Which has a methodgetValue()
method defined to return the amount in float. So to just get the amount:I haven't tried this code snippet on
list.phtml
. But it should work as long as $_product is an instance ofMagento\Catalog\Model\Product\Interceptor
.