0

I would like to override vendor/magento/module-configurable-product/Pricing/Render/TierPriceBox.php in my extension, but failed to do so so far.

So, how can I override that class?

Thanks!

0

1 Answer 1

2

You can add this code into your module :

Create the di.xml file into your module Vendor/Module/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\ConfigurableProduct\Pricing\Render\TierPriceBox" type="Vendor\Magento\Pricing\Render\TierPriceBox" />
</config>

Create the TierPriceBox.php file in following path Vendor/Module/Pricing/Render/TierPriceBox.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Pricing\Render;

use Magento\Catalog\Pricing\Price\TierPrice;

/**
 * Responsible for displaying tier price box on configurable product page.
 */
class TierPriceBox extends \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox
{
    /**
     * @inheritdoc
     */
    public function toHtml()
    {
        // Hide tier price block in case of MSRP or in case when no options with tier price.
        if (!$this->isMsrpPriceApplicable() && $this->isTierPriceApplicable()) {
            return parent::toHtml();
        }
        return '';
    }

    /**
     * Check if at least one of simple products has tier price.
     *
     * @return bool
     */
    private function isTierPriceApplicable()
    {
        $product = $this->getSaleableItem();
        foreach ($product->getTypeInstance()->getUsedProducts($product) as $simpleProduct) {
            if ($simpleProduct->isSalable() &&
                !empty($simpleProduct->getPriceInfo()->getPrice(TierPrice::PRICE_CODE)->getTierPriceList())
            ) {
                return true;
            }
        }
        return false;
    }
}
1
  • Thats working, thanks! Commented Jun 28 at 8:12

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.