You are currently viewing Calculation of shipping charges using two third party APIs and used them in Magento’s checkout process.

Calculation of shipping charges using two third party APIs and used them in Magento’s checkout process.

  • Post published:May 14, 2014

Tahir-Yasin---Magento-Checkout-ProcessClient sent the requirements to integrate two third party APIs (UPS & World Wide Express) for calculations of shipping charges in Magento’s one page checkout process. Several product attributes were to be taken care of while calculating the shipping charges.

Technical Challenges:

vteams developer Tahir had to calculate shipping charges based on combined dimensions of all the products added to the shopping cart. Magento’s built in shipping methods were not useful at all for these requirements. Tahir searched for suitable plugins but the available plugin were not meeting the requirements either.

Solution:

Tahir created a custom solution by overriding the flat rate method, injected the calculated rate there, and added a rewrite rule in module’s configuration file. Following are the details about the solution:

  1. Created a custom model Flatrate.php in:
    app/code/local/Namespace/ModuleName/model/

    class Namespace_ModuleName_Model_Flatrate extends
     Mage_Shipping_Model_Carrier_Abstract implements
     Mage_Shipping_Model_Carrier_Interface
     {
     protected $_code = 'flatrate';
     public function collectRates(Mage_Shipping_Model_Rate_Request $request)
     {
     if (!$this->getConfigFlag('active'))
     {
     return false;
     }
     // API call and rest of the logic
     }
     }
  2. Added a rewrite rule to override core model in module’s config.xml file:
    app/code/local/Namespace/ModuleName/etc/

    <global>
         <models>
            <shipping>
              <rewrite>
                <carrier_flatrate>
                   Namespace_ModuleName_Model_Flatrate
                </carrier_flatrate>
              </rewrite>
            </shipping>
         </models>
    </global>

Conclusion:

With the help of above mentioned solution, the shipping rates were calculated via third party APIs and seamlessly injected in Magento’s one page checkout process.