cancel
Showing results for 
Search instead for 
Did you mean: 

How to override magento2 product tierprice calculation ?

How to override magento2 product tierprice calculation ?

Hello All,

 

I want to override magento2 product tier price calculation 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 in order to achieve this.

 

Thank you

2 REPLIES 2

Re: How to override magento2 product tierprice calculation ?

Hi @sayanth_k 

You will achieve by the plugins.

Create a di.xml on following path:

Vendor/ModuleName/etc/di.xml

<type name="Magento\Catalog\Model\Product">
<plugin name="after_final_price" type="Vendor\ModuleName\Plugin\ChangeTierPrice" sortOrder="999" disabled="false" />
</type>

Create a plugin file:
Path:Vendor\ModuleName\Plugin\ChangeTierPrice.php

<?php

namespace Vendor\ModuleName\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);

    }    
}


It may help you to resolve your issue.

If issue resolve, please click on 'Kudoes' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: How to override magento2 product tierprice calculation ?

I tried your code but the function is not getting called.