Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magento Adapter Class for Shipping

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 299
    Comment on it

    The adapter model handles the functionality for our shipping module. This is where all the calculations happen and where everything will be coded. The coding written in model is to handle the shipping methods and the rates returned to the user for checkout process.

    To create our shipping carrier, we need to extend Mage_Shipping_Model_Carrier_Abstract, implement Mage_Shipping_Model_Carrier_Interface and add the required abstract methods. The most important method is collectRates and getAllowedMethods. collectRates is the method that receives a shipping request, appends applicable shipping methods and returns a shipping result. Below is the sample code :-

    class PackageName_ModuleName_Model_Carrier_Myshipping extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
    {
        protected $_code = 'modulename';
    
        public function collectRates(Mage_Shipping_Model_Rate_Request $request)
        {
            if (!$this->getConfigFlag('active')) {
                return false;
            }
    
            $handling = $this->getConfigData('handling');
            $result = Mage::getModel('shipping/rate_result');
            foreach ($response as $method) {
                $rMethod = Mage::getModel('shipping/rate_result_method');
    
                $method->setCarrier($this->_code);
                $method->setCarrierTitle($this->getConfigData('title'));
    
                $method->setMethod($method['code']);
                $method->setMethodTitle($method['title']);
    
                $method->setCost($method['amount']);
    
                $method->setPrice($method['amount']+$handling);
    
                $result->append($method);
            }
        return $result;
        }
    
        public function getAllowedMethods()
        {
            return array('custom_shipping' => $this->getConfigData('name'));
        }
    }

    Where replace with your package name and with your module name.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: