1

I have created a custom shipping module and have defined collectRates() and other functions in the module.

I also have onepage checkout enabled. In that page this new shipping module is not getting called. The shipping amount is coming blank.

What do I have to do to get my checkout page and my cart page to automatically call this module to show the right shipping price?

I am using Magento 1.9.2

My carrier class is:

<?php

// app/code/local/Envato/Customshippingmethod/Model
class Shopez_Customshippingmethod_Model_Demo
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'shopez_customshippingmethod';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        $result = Mage::getModel('shipping/rate_result');
        $result->append($this->_getDefaultRate());
        return $result;
    }

    public function getAllowedMethods()
    {
        return array(
            'shopez_standard' => 'Delivery Based on Cart Subtotal',
        );
    }

    protected function _getDefaultRate()
    {
        $rate = Mage::getModel('shipping/rate_result_method');

        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod($this->_code);
        $rate->setMethodTitle('Delivery Based on Cart Subtotal');
        $rate->setPrice($this->getConfigData('price'));
        $rate->setCost(0);
        return $rate;
    }

    protected function _getStandardRate()
    {
        /** @var Mage_Shipping_Model_Rate_Result_Method $rate */
        $rate = Mage::getModel('shipping/rate_result_method');

        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod('large');
        $rate->setMethodTitle('Delivery Based on Cart Subtotal');
        $rate->setPrice(1.23);
        $rate->setCost(0);
        return $rate;
    }

}
  • Consider your magento version – Asish Hira Apr 21 '16 at 11:35
  • 1
    Can you paste your Carrier class? – Shyam Apr 21 '16 at 12:21
0

Your Carrier Class should be as below:

app/code/local/Namespace/Customshippingmethod/Model

<?php

// app/code/local/Namespace/Customshippingmethod/Model
class namespace_Customshippingmethod_Model_Demo
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'namespace_customshippingmethod';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        $result = Mage::getModel('shipping/rate_result');
        $result->append($this->_getDefaultRate());

        return $result;
    }

    public function getAllowedMethods()
    {
        return array(
            'namespace_customshippingmethod' => $this->getConfigData('name'),
        );
    }

    protected function _getDefaultRate()
    {
        $rate = Mage::getModel('shipping/rate_result_method');

        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod($this->_code);
        $rate->setMethodTitle($this->getConfigData('name'));
        $rate->setPrice($this->getConfigData('price'));
        $rate->setCost(0);

        return $rate;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.