1

I had created a custom shipping module. But when I enable it and check on the frontend for my custom shipping rate, then I add billing detail and click on the Continue button, it redirects me to the cart page.

Here is the code of my custom shipping module.

app/etc/modules/Custom_ShippingMethod.xml

<config>
    <modules>
        <Custom_ShippingMethod>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Shipping />
            </depends>
        </Custom_ShippingMethod>
    </modules>
</config>

app/code/local/Custom/ShippingMethod/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_ShippingMethod>
            <version>1.0</version>
        </Custom_ShippingMethod>
    </modules>
  <global>
        <models>
            <customshippingmethod>
                <class>Custom_ShippingMethod_Model</class>
            </customshippingmethod>
        </models>
        <helpers>
          <customshippingmethod>
            <class>Custom_ShippingMethod_Helper</class>
          </customshippingmethod>
        </helpers>
    </global>
    <default>
        <carriers>
          <customshippingmethod>
               <active>1</active>
               <model>shipping/carrier_customshippingmethod</model>
               <title>Custom Shipping Carrier</title>
               <name>My Custom Shipping Method</name>
               <price>5.00</price>
               <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
            </customshippingmethod>
         </carriers>
       </default>
</config>

app/code/local/Custom/ShippingMethod/etc/system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <carriers>
            <groups>
                <customshippingmethod translate="label" module="shipping">
                    <label>Custom Shipping</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </active>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </title>
                        <name translate="label">
                            <label>Method Name</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </name>
                        <price translate="label">
                            <label>Price</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </price>
                        <specificerrmsg translate="label">
                            <label>Displayed Error Message</label>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </specificerrmsg>
                        <sallowspecific translate="label">
                            <label>Ship to Applicable Countries</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>90</sort_order>
                            <frontend_class>shipping-applicable-country</frontend_class>
                            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sallowspecific>
                        <specificcountry translate="label">
                            <label>Ship to Specific Countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>91</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                    </fields>
                </customshippingmethod>
            </groups>
        </carriers>
    </sections>
</config>

app/code/local/Custom/ShippingMethod/Model/Customshipping.php

<?php
class Custom_ShippingMethod_Model_Customshipping extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{

    protected $_code = '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(
            '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;
    }
}

app/code/local/Custom/ShippingMethod/Helper/Customshipping.php

<?php
class Custom_ShippingMethod_Helper_Customshipping extends Mage_Core_Helper_Abstract
{

}

I got my custom shipping module configuration like this in admin. Please check the attached screenshot. enter image description here

But on the frontend when I add the product to cart and go to checkout, after filliing up the billing info and click on "Continue" for Shipping Method. Then I am getting redirected on the cart page.

Can anybody suggest me where I am wrong. I had reffered this article.

  • did you check custom shipping also enable at store level ? – Pawan Dec 6 '19 at 2:34
  • Yes @Pawan, I had checked the custom shipping method and it is enabled for all stores. – MagentoUser Dec 6 '19 at 4:58
  • i checked your code, please see my answer. it will work for you. – Pawan Dec 6 '19 at 5:00
1

I checked your code and found following error at:

app/code/local/Custom/ShippingMethod/etc/config.xml

  1. You need change model in <customshippingmethod> tag from <model>shipping/carrier_customshippingmethod</model> to <model>shippingmethod/customshipping</model>

Explanation: model name and path is wrong and it should be [modulename]/[path_to_model]

  1. helper and model class should be in module tag i.e <shippingmethod> not <customshippingmethod>

I am attaching diff of file

enter image description here

Correct file should be:

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_ShippingMethod>
            <version>1.0</version>
        </Custom_ShippingMethod>
    </modules>
  <global>
        <models>
            <shippingmethod>
                <class>Custom_ShippingMethod_Model</class>
            </shippingmethod>
        </models>
        <helpers>
          <shippingmethod>
            <class>Custom_ShippingMethod_Helper</class>
          </shippingmethod>
        </helpers>
    </global>
    <default>
        <carriers>
          <customshippingmethod>
               <active>1</active>
               <model>shippingmethod/customshipping</model>
               <title>Custom Shipping Carrier</title>
               <name>My Custom Shipping Method</name>
               <price>5.00</price>
               <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
            </customshippingmethod>
         </carriers>
       </default>
</config>

Hope above will Help!

|improve this answer|||||
  • Hii @Pawan, Thanks for checking my code and providing me the solution to sort out my problem. I had applied your solution and changed the module tags for Model and Helper. But the problem doesn't get fixed. Still, I am facing the same issue with my custom shipping method. – MagentoUser Dec 6 '19 at 5:21
  • just copy file i provided in answer, it will work. – Pawan Dec 6 '19 at 5:26
  • I had copied and pasted your answer but still, it didn't get the solution for me. When I disable my custom shipping module the checkout shipping works fine and when I enable it again, then I am facing the same issue. I had checked my whole modules code 15 to 20 times and compared it with the blogs and google solutions. Also, I had applied your solution but I am facing the same issue. I am not getting where did I had made wrong. – MagentoUser Dec 6 '19 at 5:43
  • Thanks @Pawan for giving me solution with explanation. Actually your solution is correct but I don't know why it does not provide a fix for my issue. – MagentoUser Dec 6 '19 at 5:47
  • 1
    please find whole code at github.com/pawankparmar/customshipping and let me know if have any issue. – Pawan Dec 6 '19 at 6:05

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.