How is a price rendered on a frontend product view page in Magento 2?
Dmitry Fedyuk illustrates how a price is rendered on a frontend product view page in Magento 2 with the help of the following code:

Table of contents [hide]
- 1 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml#L55-L61
- 2 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/default.xml#L10-L16
- 3 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L92
- 4 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml#L9-L38
- 5 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L98
- 6 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L59
- 7 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L227-L241
- 8 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml#L23-L26
- 9 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L66
- 10 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product.php#L1079-L1090
- 11 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product/Type.php#L161-L170
- 12 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/PriceInfo/Factory.php#L56-L87
- 13 magento/magento2/blob/2.0.0/app/code/Magento/ConfigurableProduct/etc/di.xml#L77-L81
- 14 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L79
- 15 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L85
- 16 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L99
- 17 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/final_price.phtml#L17
- 18 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/final_price.phtml#L44
- 19 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/PriceBox.php#L114-L125
- 20 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/PriceBox.php#L127-L140
- 21 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L142
- 22 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L148
- 23 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L187-L202
- 24 magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/amount/default.phtml#L24
- 25 magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/Amount.php#L214-L228
- 26 magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/PriceCurrency.php#L73-L82
- 27 magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/PriceCurrency.php#L114
- 28 magento/magento2/blob/2.0.0/app/code/Magento/Store/Model/Store.php#L940-L955
- 29 magento/magento2/blob/2.0.0/app/code/Magento/Store/Model/Store.php#L867-L886
- 30 magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/Currency.php#L277-L294
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml#L55-L61
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/default.xml#L10-L16
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L92
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml#L9-L38
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L98
Note that
-
$priceCode
isfinal_price
on a catalog product view; $type
is a product type (e.g.grouped
).
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L59
Ad as for $renderClassName, it may
be \Magento\Catalog\Pricing\Render\FinalPriceBox
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L227-L241
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml#L23-L26
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L66
As for $price, it
may be \Magento\ConfigurableProduct\Pricing\Price\FinalPrice
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product.php#L1079-L1090
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/Model/Product/Type.php#L161-L170
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/PriceInfo/Factory.php#L56-L87
Note that:
$priceInfo
may beMagento\Framework\Pricing\PriceInfo\Base ;$priceCollection
–\Magento\ConfigurableProduct\Pricing\Price\Collection .
magento/magento2/blob/2.0.0/app/code/Magento/ConfigurableProduct/etc/di.xml#L77-L81
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L79
As for $renderBlock, it
may be \Magento\Catalog\Pricing\Render\FinalPriceBox
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L85
The expected result may look like Magento_Catalog::product/price/final_price.phtml
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render.php#L99
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/final_price.phtml#L17
$priceModel not only
supports the \Magento\/Framework\Pricing\Price\PriceInterface
\Magento\ConfigurableProduct\Pricing\Price\ConfigurableRegularPrice
Note that a PHPDock comment for the $priceModel variable should be:
The $priceModel may be, for example, an instane of the \Magento\ConfigurableProduct\Pricing\Price\ConfigurableRegularPrice class, which is not a descendant of the \Magento\Catalog\Pricing\Price\RegularPrice class.
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/final_price.phtml#L44
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/PriceBox.php#L114-L125
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/PriceBox.php#L127-L140
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L142
As for $amountBlock, it
could be an instance of the \Magento\Framework\Pricing\Render\Amount
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L148
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/RendererPool.php#L187-L202
Possible result is Magento_Catalog::product/price/amount/default.phtml
magento/magento2/blob/2.0.0/app/code/Magento/Catalog/view/base/templates/product/price/amount/default.phtml#L24
magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Pricing/Render/Amount.php#L214-L228
magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/PriceCurrency.php#L73-L82
magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/PriceCurrency.php#L114
magento/magento2/blob/2.0.0/app/code/Magento/Store/Model/Store.php#L940-L955
magento/magento2/blob/2.0.0/app/code/Magento/Store/Model/Store.php#L867-L886
magento/magento2/blob/2.0.0/app/code/Magento/Directory/Model/Currency.php#L277-L294
More tips from Magento 2 cookbook
