Shipping Modules in Magento: Part 2

8 min read

Appearing in the administration

Once this has been done, the shipping method should appear in Shipping Methods under System->Configuration:

Magento 1.3: PHP Developer's Guide

Now, we will look at the most useful shipping module fields that are used when putting the shipping module together. These are fields with predefined names and types that have automatically processed the results that they output. Therefore, they require no additional coding in the adaptor module to take them on board; Magento performs these methods straight out of the box.

Free shipping

If we want to enable an automatic price-based amount for free shipping with our method, we can add in a field called free_shipping_enable and combine this with another field by the name of free_shipping_subtotal. When free_shipping_enable is set to Enabled by the Magento administrator, then Magento will automatically take free_shipping_subtotal into account and offer free shipping if the total amount is above the value of free_shipping_subtotal.

If this field is disabled, Magento will simply process using the default shipping calculation behavior of the module.


The fields are set up as follows, with sort_order and show_in_ values varying:

<free_shipping_enable translate="label">
<label>Free shipping with minimum order amount</label>
<free_shipping_subtotal translate="label">
<label>Minimum order amount for free shipping</label>


Handling charges sometimes come into the equation and need to be added onto the overall transaction. Magento enables us to do this using the following source models to present what we want to achieve:

<handling_type translate="label">
<label>Calculate Handling Fee</label>
<handling_action translate="label">
<label>Handling Applied</label>
<handling_fee translate="label">
<label>Handling fee</label>

Restricting a shipping method to certain countries

This will allow us to present the option to the administrator for filtering the shipping method to be only accessible to certain countries. In practice, this means that if we wanted to offer only one type of delivery to the United Kingdom, then we could do so simply by selecting United Kingdom from the multi-select field created by the following declaration.

The Magento administrator can choose the specific countries from the multiple select list. Only orders from those countries that we have created shipping methods for will be processed in the shipping module. This enables them to choose any number of countries for restricting this shipping method to .

sallowspecific translate="label">
<label>Ship to applicable countries</label>
<specificcountry translate="label">
<label>Ship to Specific countries</label>
<showmethod translate="label">
<label>Show method if not applicable</label>

Using our template to create a shipping method

Now that we have our bare-bones shipping module, we continue with the creation of something that we can see an outcome from. From this we should be able to start to put together our own shipping module tailor-made for future needs.

The purpose of what we are going to build is going to be very simple: we’re going to create a shipping module that meets the following parameters:

  • It has a handling fee, either per product or for the entire order
  • It can be limited to specific countries
  • It can set a simple flat-rate shipping cost, if 10 products or more are being ordered
  • It can set another simple flat-rate shipping cost, if 10 products or less are being ordered
  • All of the above can be configured via the Magento administration

Before progressing, we delete the previous shipping module from our installation to make sure that it does not interfere with what we’ll be building. To do this, we go back to the Magento Downloader  and select Uninstall from the module’s supporting dropdown before committing the changes.

The configuration files

This time, we’ll go with the directory MagentoBook and the name FullShippingModule. For this, our /app/code/local/MagentoBook/ShippingModule/MagentoBook/FullShippingModule/etc/config.xml file will look like:

<?xml version="1.0"?>
<Mage_Shipping />



We turn on FullShippingModule, and allow it to be turned off/on from within the administration. Then, we create /app/etc/modules/MagentoBook_FullShippingModule.xml and place the following in it:

<?xml version="1.0"?>

Our adaptor

For those interested in cutting down on code, unnecessary comments have been removed (which were included in the previous adaptor in this article).

We place the following code in: /app/code/local/MagentoBook/FullShippingModule/Model/Carrier/FullBoneMethod.php

class MagentoBook_FullShippingModule_Model_Carrier_FullBoneMethod
extends Mage_Shipping_Model_Carrier_Abstract
protected $_code = 'fullshippingmodule';
public function collectRates(Mage_Shipping_Model_Rate_Request
if (!$this->getConfigData('active')) {
Mage::log('The '.$this->_code.' shipping method is not
return false;
$handling = $this->getConfigData('handling');
$result = Mage::getModel('shipping/rate_result');
$method = Mage::getModel('shipping/rate_result_method');
$items = Mage::getModel('checkout/session')->getQuote()-
if (count($items) >= $this->getConfigData('minimum_item_limit')) {
$code = $this->getConfigData('over_minimum_code');
$title = $this->getConfigData('over_minimum_title');
$price = $this->getConfigData('over_minimum_price');
else {
$code = $this->getConfigData('under_minimum_code');
$title = $this->getConfigData('under_minimum_title');
$price = $this->getConfigData('under_minimum_price');
$method->setPrice($price + $handling);
return $result;

In short, this will check whether there are more items in the cart than the pre-configured value of minimum_item_limit and then apply a rate if it is over the set limit. If under the limit, it applies another rate.


Please enter your comment!
Please enter your name here