문제

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?

도움이 되었습니까?

해결책

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>";
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top