Search code examples
phpmagentomagento2

Change final shipping rate based on the product weight in magento


I am using table rate for shipping methods configuration.

enter image description here

But the final shipping rate will change based on the product weight.

Final shipping rate=Shipping rate*Product weight

For Ex: If the prdouct weight=6kg,Final shipping rate will be 6*100 if the prdouct weight=11kg,Final shipping rate will be 11*90.

How can i achieve this feature?


Solution

  • Please do a modification on this file

    app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

    change line 166 from,

    $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
    

    to

    $shippingPrice = ($rate['price']*$request->getPackageWeight());