If you want to customize Magento 2 tier prices on configurable product pages, you may need to override the vendor/magento/module-configurable-product/Pricing/Render/TierPriceBox.php class. Here is how:
Add the following content to the di.xml file in your extension:
|
1 2 3 |
<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\Module\Pricing\Render\TierPriceBox" /> </config> |
Now create the class TierPriceBox.php at the following path: Vendor/Module/Pricing/Render/TierPriceBox.php
Add the following code to the new class and customize the relevant parts as needed. toHtml() Funktion an:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?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; } } |
Overriding TierPriceBox.php for configurable products
Need help implementing this solution, or still looking for a fix to your Magento problem? Get in touch and I will be happy to help with your project.