0

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?

1 Answer 1

1

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>";
    }
}
12
  • how we can apply this code ? it will not work Jan 18, 2020 at 13:52
  • i have tried its not working Jan 18, 2020 at 13:52
  • I have added this code and its working fine for me, Check this screenshot: prntscr.com/qph7j6 Jan 18, 2020 at 14:09
  • What error you are getting? Jan 18, 2020 at 14:10
  • 1
    I have added just under the <?= /* @escapeNotVerified */ $block->getProductPrice($_product) ?> : prntscr.com/qphpm0 Jan 18, 2020 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.