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?

2 Answers 2

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

By default, Magento shows tier prices only on the Product Details page.

To show tier prices on cart pages, Please add the code below to the default.phtml file.

To show on the catalog page please add the code to the list.phtml file.

Tested on Magento 2.4.7

In the catalog page use variable $_product instead of $product. This will show same as product page.

<?php
        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 = 100 - ceil((100 / $product->getFinalPrice()) * $value['price']) . "%";
                echo "Buy $qty for " . $formattedTierPrice . " each and save " . $savePercentage . "<br>";
            }
        }
        ?>

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.