Pregunta

Tier price is working fine on the product page, but when we try to show on the listing page then it's not working.

<?php /* @escapeNotVerified */ echo ($block->getShowDetailedPrice() !== false)
                        ? __(
                            'Buy %1 for %2 each and <strong class="benefit">save<span class="percent tier-%3">&nbsp;%4</span>%</strong>',
                            $price['price_qty'],
                            $priceAmountBlock,
                            $index,
                            $tierPriceModel->getSavePercent($price['price'])
                        )
                        : __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock);
                ?>

Can anyone help me?

¿Fue útil?

Solución

By default Magento shows tier prices only on Product Details pages, To show tier prices on category pages, Please add below code to your list.phtml file

if($_product->getTierPrice()){
    $tierPrice = $_product->getTierPrice();
    foreach ($tierPrice as $key => $value) {
        $qty = (int)$value['price_qty'];
        $price = $value['price'];
        $formattedTierPrice = $this->helper('Magento\Framework\Pricing\Helper\Data')->currency(number_format($price, 2), true, false);
        $savePercentage = ceil(100 - ( (100 / $_product->getPrice())* $value['price']) ) ."%";
        echo "Buy $qty for ".$formattedTierPrice." each and save ".$savePercentage."<br>";
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top