Our customer would like to display lowest possible price in product list pages. All visible products in website are bundle products
This is the function which displays the price
Magento\Catalog\Block\Product\ListProduct
public function getProductPrice(\Magento\Catalog\Model\Product $product)
{
$priceRender = $this->getPriceRender();
$price = '';
if ($priceRender) {
$price = $priceRender->render(
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
$product,
[
'include_container' => true,
'display_minimal_price' => true,
'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
'list_category_page' => true
]
);
}
return $price;
}
The fast try (changing \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE to \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE) obviously doesn't work, as TierPrice should return an array or some complex data and not a price amount
How to achieve this? Any tips?
update
Missed to comment that products in catalog are bundle
Best Answer
Already forces the lowest price to be displayed in your list (as a link), you don't have to change the price code, if tierprice is the lowest possible price.
Example:
If you only want the minimal price to be displayed in your list, you have to create a new Magento\Catalog\templates\product\price\final_price.phtml in your custom theme and only display the final_price if
!$block->hasSpecialPrice())
and!$block->showMinimalPrice()
Edit: possible solution for bundled products/ just an idea, no time at the moment to check it but maybe it helps you
Define a new custom price renderer in your di.xml, so you will only change the behavior in list and don't change bundle product pricing core function
Define render template for your price renderer in catalog_product_prices.xml
In your BundleLowestPrice.php get the final price for each bundle option (as simpleproduct) and compare them, return the lowest possible price to your bundle/final_price.phtml
4.final_price.phtml: