Fixing Magento Shipping Handling Fee Percentage of Order

07

Nov

Fixing Magento Shipping Handling Fee Percentage of Order

So, if you have ever tried to set a handling fee in Magento by percent per order, you’ll find it takes the shipping cost * the handling (even though in the docs it says it takes the order * the handling). However, I have a client who needed to have their shipping charge a percentage of the order total to recoup the cost for insurance for UPS shipping since the module doesn’t have that feature.

So, here’s how to fix this:

1. Copy /app/code/core/Mage/Shipping/Model/Carrier/Abstract.php to /app/code/local/Mage/Shipping/Model/Carrier/Abstract.php (we never want to modify the core. EVER!).

Open of that new file and replace the following line:

return ($cost * $this->_numBoxes) + ($cost * $this->_numBoxes * $handlingFee / 100);

with:

$ordertotalforshipping = Mage::getSingleton(‘checkout/session’)->getQuote();
return ($cost * $this->_numBoxes) + ($ordertotalforshipping * $handlingFee);

Save the file.

Now, as long as you have selected the options in your shipping module, it should work.

2 thoughts on - Fixing Magento Shipping Handling Fee Percentage of Order

  • Ben
    Sep 23, 2015 at 10:08 pm

    This is great, thank you. But I am not getting it to work so far.

    My Magento in 1.9.0.1 in case that matters.

    Is this path correct:
    /app/etc/code/core/Mage/Shipping/Model/Carrier/Abstract.php ?

    Shouldn’t it be:
    /app/code/core/Mage/Shipping/Model/Carrier/Abstract.php ?

    And shouldn’t the “to” path be:
    /app/code/local/Mage/Shipping/Model/Carrier/Abstract.php ?

    I have made these changes but it seems to be still using the original math, basing the percentage on the shipping cost rather than on the order total.

    Is it enough just to override that one file? The rest of the local directory tree is basically empty in my case.

    If you have any suggestions I’d love to hear them but I understand if youre on to new things!

    And thanks again for putting this up.

    Ben

    • dwdonline
      Sep 28, 2015 at 4:26 am

      You’re right – I had /etc/ in there. I changed that. That should be the only place you need to change it. Are you running any other extensions that are overwriting it?

      I’d check the path to make sure it’s the same (changing core to local), and then make sure you’ve cleared your cache. If need be, remove the var/cache and maybe var/session. And, of course, if you have any full page cache, varnish, etc., you need to clear that as well. If it’s a dedicated or cloud, reboot.

Leave a Reply