Magento – Stop Magento from automatically updating Shipping Quote

cartquoteshipping

Magento's default behavior seems to be to update a shipping quote for every single modification to a shopping cart. I find this very undesirable because it can cause the shopping experience to become unnecessarily slow while Magento waits from quotes from all carriers.

Magento also seems to be very loose on what it calls a "Quote", with there being Sales Quotes and Checkout Quotes. So, even though I have very little experience working with Magento Events, I am having a hard time figuring out where to even start.

How do I stop Magento from getting a shipping quote for every item added or removed from the cart? Just a point in the right direction would be a big help.

Best Answer

I had a similar issue, where shipping lookups were done via australia post (using the fontis australia module located here:

https://github.com/fontis/fontis_australia

If you dig a bit further, you'd most likely find that the lookup also happens via checkout, which is unnecessary, as the quote has not changed.

I implemented a fix (which was merged into the fontis module) a while back, which does a simple cache of the lookup in the session, and re-uses that on subsequent requests.

from: https://github.com/fontis/fontis_australia/blob/master/app/code/community/Fontis/Australia/Model/Shipping/Carrier/Australiapost.php

/**
                 * Lucas van Staden @ doghouse media 
                 * Add a drc call cache to session. (valid for 1 hour)
                 * The call to drc is made at least 3-4 times, using the same data (ugh)
                 *  - Add to cart (sometimes * 2)
                 *  - Checkout * 2
                 * 
                 * Create a lookup cache based on FromPostcode->ToPostcode combination, and re-use cached data
                 * The end result will kill lookups in checkout process, as it was actually done at cart, which will speed checkout up.
                 */


            $drcCache = Mage::getSingleton('checkout/session')->getDrcCache();
            if(!$drcCache) {
                $drcCache = array();
            } else {
                // wrap it in a try block, s it is used durng checkout.
                // prevents any mistake from stopping checkout as a new lookup will be done.
                try {
                    $time = time();
                    if($this->getConfigFlag('cache') 
                            && array_key_exists($fromPostCode, $drcCache) 
                            && array_key_exists($toPostCode, $drcCache[$fromPostCode])
                            && $time - $drcCache[$fromPostCode][$toPostCode]['timestamp'] < 3600) {
                        if ($this->getConfigFlag('debug')) {
                            Mage::log('Using cached drc lookup for ' . $fromPostCode . '/' . $toPostCode, null, 'fontis_australia.log');
                        }
                        return $drcCache[$fromPostCode][$toPostCode]['result'];
                    }
                } catch (Exception $e) {
                    mage::logException($e);
                }   
            }

You would most likely need to implement something similar (at the cart level) in the provider module you are using. The fix above was to solve the lookups causing checkout to take very long, when the provider was busy.

Related Topic