Magento Certified Developer GuideCategory: 8. CheckoutDescribe the programmatic structure of shipping methods, how to customize existing methods, and how to implement new methods
Manish Prakash Staff asked 2 years ago

Structure Of Shipping Methods

Shipping methods are defined in config.xml file as below

<global>
   <default>
       <carriers>
           <flatrate>
                <active>1</active>
                <sallowspecific>0</sallowspecific>
                <model>shipping/carrier_flatrate</model>
                <name>Fixed</name>
                <price>5.00</price>
                <title>Flat Rate</title>
                <type>I</type>
                <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
                <handling_type>F</handling_type>
            </flatrate>
       </carriers>
   </default>
</global>

Here we specify the shopping method code and model.
Next we need to define the system.xml configuration parameters, so the shipping method shows up in system configuration.

Next important thing is to define the model

class Mage_Shipping_Model_Carrier_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;
        }
        return parent::collectRates($request);
   }
   public function getAllowedMethods()
    {
        return array('flatrate'=>$this->getConfigData('name'));
    }
}