Question

I want to override magento2 product tier price calcualtion logic for price type 'Percentage'. I would like to calculate the percentage amount in my own way. Please let me know which file I have to override inorder to achieve this.

Thank you

Was it helpful?

Solution

You will achieve by the plugins.

create a di.xml on following path:

Company/Module/etc/di.xml

<type name="Magento\Catalog\Model\Product">
     <plugin name="after_final_price" type="Company\Module\Plugin\ChangeTierPrice" sortOrder="999" disabled="false"  />
</type>
<type name="Magento\Catalog\Pricing\Price\FinalPrice">
      <plugin name="after_final_price_info" type="Company\Module\Plugin\ChangeTierPriceInfo" sortOrder="999" disabled="false"  />
</type>

Create a plugin file:

Company\Module\Plugin\ChangeTierPrice.php

<?php

namespace Company\Module\Plugin;

class ChangeTierPrice
{        
    public function beforeGetFinalPrice($subject, $qty = null)
    {
        $finalTierPrice = [];
        //You need to create your own array or modify the default tier price here and set in to product object
        $subject->setData('tier_price', $finalTierPrice);

    }    
}

Create a plugin file:

Company\Module\Plugin\ChangeTierPriceInfo.php

<?php

namespace Company\Module\Plugin;

class ChangeTierPriceInfo
{        
    public function beforeGetValue($subject)
    {
        $finalTierPrice = [];
        //You need to create your own array or modify the default tier price here and set in to product object
        $product = $subject->getProduct();
        $product->setData('tier_price', $finalTierPrice);

    }    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top