Page tree
Skip to end of metadata
Go to start of metadata



This tutorial is similar to Creation of Payment Method module, and differs the most in adapter model.

Each shipping method can be done as separate module or few methods can be combined in same module if they share functionality or could be used together.

Our new module will be called NewModule.

Replace all instances of ‘NewModule’ with name of your module and ‘newmodule’ with simplified code, that contains only alphanumeric characters and underscore.

Replace all instances of ‘YourCompany’ with your company name or whatever name you choose.

To make this tutorial most concise, it’s implied that mentioned folders will be created when needed.

Make sure that app/code/local is in PHP‘s include_path. To do so, execute the following code, either in a shell or inside a web-accessible PHP file:

  1. <?php echo get_include_path();?>

Make sure you put this code somewhere after Magento was loaded, at the bottom of index.php for example, because Magento might modify the include_path on its own to fit its needs and dynamically attribute locations.

If you are using configuration cache, don’t forget to clean it after modifying config xml files.



Create app/code/local/YourCompany/NewModule/etc/config.xml:

 Expand source
Create app/etc/modules/YourCompany_NewModule.xml:


 Expand source


Note: using “<!– ... –>” could imply there is more to input here, but for newbies like me, this is confusing if there is actually nothing to input. Also, I have seen some modules with <depends> <Mage_Shipping /> </depends> within the <YourCompany_NewModule> section. Should this be suggested?

Now application is aware of the module, but nothing will happen until we’ll create model logic!

Adapter model


Note: ShippingMethod name is arbitrary and is up to your decision.

Create app/code/local/YourCompany/NewModule/Model/Carrier/ShippingMethod.php:

 Expand source

Now that we have the model let’s give admin a way to configure it and also make checkout process aware of this method.

Admin Configuration Implementation


In this step, we need to tell Magento how to display our module in the Configuration section of the administrative panel. In order to do so, we must create app/code/local/YourCompany/NewModule/etc/system.xml and make it look something like this:

 Expand source

You should now see your module in the Administration under “System” > “Configuration” > “Shipping Methods”. It’s now up to you to add your custom fields in the <fields> tag, and subsequently make your configuration do something constructive.

Common Problems


Here is a list of things that have happened to others while trying to implement thier own Shipping Module. (Please add to this list or provide responses to unresolved issues if you can. A collection of common problems and how to avoid them can only help everybody.)

Module won’t activate

Relating to the importance of casing, be sure the CompanyName you use has an initial cap letter - a lowercase initial letter will prevent this from activating. Magento really needs to have clear documentation for these norms.

This code doesn’t work on

In adminhtml all work. But model class doesn’t load. How to tell Magento in config.xml, system.xml or anywhere else to load this model class?

Module doesn't appear in frontend.

I’ve just managed to get this to work, with a bit of hacking. I had created a method following the instructions above, but couldn’t get it it give me a quote on the front end. The problem was in app/core/Mage/Shipping/Model/Shipping.php, line 164:

$className = Mage::getStoreConfig('carriers/'.$carrierCode.'/model', $storeId);

The module didn’t have a ‘model’ defined for it, so the getCarrierByCode() method was returning false straight away. The hack involved creating a new field in the system.xml file:

<model translate="label">

Then, using the admin panel, I gave this a value of ‘newmodule/carrier_newmodule’. While I was there I also created a ‘name’ field to give the method a name.

After doing that, the method was appearing in my list of quotes! — David Edwards 2008/07/28 10:26

I found another solution: insert the following code into config.xml right below the config -tag:

 Expand source

Module doesn't appear in admin.

Check to make sure that you have the system.xml and config.xml files in the suggested directory structure. Capitalization appears to be important. Be careful not to use “locale” where you meant to use “local”.

Backend shows errormessage when displaying the shippingmethod

Make sure that the content in every <source_model> - tag has no line-break.





I get this error: -

Notice: Undefined variable: response in /var/www/vhosts/ on line 37

which happens to be this line : " foreach ($response as $rMethod) {

any ideas?

Please, can you describe where exactly should I change the name from NewModel to Newmodel for to make this work in

For about two years does anybody find this solution? This code does not work with magento maybe this fact should be mentioned.

Hi, i got the same error “undefine variable response”. Does anyone know the solution for this?


by tariqc

Looks like a line is missing that should have initialized $response

foreach ($response as $rMethod) {

or maybe $response should be the $result array?

— 2012/02/29

Hey It is clear! : “$response is an array that we have” ;) lol

I think that this is considering that the response of a shipping service may return multiple methods. For example, the same service should return different rates, as ‘express shipping’, ‘3 days shipping’, etc. So, the $response variable is the result of the service call. But, if we want to return only one method with a simple rate, I think we can obviate the foreach method and considere only the main values to set the response, that I think that are these:

 $result = Mage::getModel('shipping/rate_result');
 $rate = Mage::getModel('shipping/rate_result_method');
 $rate->setMethodTitle('your method title');
 $rate->setPrice($theprice); //You should calculate this or obtain in a service 

— 2012/08/10




  • No labels