Return to Snippet

Revision: 45379
at April 29, 2011 02:34 by ef


Initial Code
$shippingAddress = $this->getQuote()->getShippingAddress();
    if (!$shippingAddress->getCountryId()) {
      $shippingAddress->setCountryId('PL')->setShippingMethod('flatrate_flatrate')->save();
      $shippingAddress->save();
    }

Initial URL

                                

Initial Description
Inspired by http://subesh.com.np/2010/08/magento-setting-default-shipping-method-cart-page/.
Basically Magento requires only countryId in shipment address to show shipment methods (at least in polish case). Very useful if you want user to select shipment method before specifying address.
This code must be put in init method of Mage_Checkout_Model_Cart or class that redefines it,  just after line 122 (after Mage_Checkout_Model_Cart {...} in other words), otherwise it won't show up in cart when user first enters it, only when he/she refershes it.

Initial Title
Setting default shipping method in Magento

Initial Tags
magento

Initial Language
PHP