Posted By

ef on 04/29/11


Tagged

checkout magento


Versions (?)

Setting default shipping method in Magento


 / Published in: PHP
 

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 MageCheckoutModelCart or class that redefines it, just after line 122 (after MageCheckoutModelCart {...} in other words), otherwise it won't show up in cart when user first enters it, only when he/she refershes it.

  1. $shippingAddress = $this->getQuote()->getShippingAddress();
  2. if (!$shippingAddress->getCountryId()) {
  3. $shippingAddress->setCountryId('PL')->setShippingMethod('flatrate_flatrate')->save();
  4. $shippingAddress->save();
  5. }

Report this snippet  

You need to login to post a comment.