How to use Magento Shipping Table Rates

With Magento you can set few kinds of shipping methods: flat rate, table rates or even real-time carrier rates from UPS, FedEx and DHL. You can also use free shipping discounts, that can be created for order amounts, or as part of specific marketing promotions.

To set shipping methods in backoffice go to System -> Configuration and choose from the left navigation "Shipping methods". When you want to use Table rates you can choose one of three conditions avalaible:

  • Weight vs. Destination
  • Price vs. Destination
  • Number of Items vs. Destination

You also need to create csv file for your table rates. You can first export one from magento to have a template. To do that you will need to change scope for your website in "Current Configuration Scope" (top left select box). Choose "Main website" for example. Then in Table rates you will be able to see "Export CSV" button.

Export table rates

Export and save tablerates.csv on your computer. The CSV file should looks like:

"Country","Region/State","Zip/Postal Code","Weight (and above)","Shipping Price"
"FRA","*","*","0.0000","11.0000
"FRA","*","*","10.0000","13.000"
"FRA","*","*","20.0000","15.0000"

Above lines define shipping rates for all regions in France. As you see weight condition is set as "from and above". So when order wieght is 0 and above (0-10 kg) shipping wil cost 11 euros, when its 10 and above (10 - 20 kg) shipping is 13 euros. When order weight is above 20 kg you will pay 15 euros for shipping. Even when it's 100 kg or 1000 kg you will still pay 15 euros! The problem with condition "from and above" is that you are unable to set maximum weight. So lets make these conditions work in "up to" way.
In "up to" way tablerates.csv like:

"Country","Region/State","Zip/Postal Code","Weight (and above)","Shipping Price"
"FRA","*","*","10.0000","13.000"
"FRA","*","*","20.0000","15.0000"

will define that for order which weight is up to 10 kg (0-10 kg) shipping cost is 13 euros. For orders up to 20 kg (10 - 20 kg) it's 15 euros. So the maximum weight for table rate is 20kg. Above 20kg you will have no table rate available.

To make table rates work that way function getRate() from Mage_Shipping_Model_Mysql4_Carrier_Tablerate needs to be overwriten. First we need to create new module under /code/local directory and configure it:

Magento module

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <shipping_mysql4>
                <rewrite>
                    <carrier_tablerate>Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate</carrier_tablerate>
                </rewrite>
            </shipping_mysql4>
        </models>
    </global>
</config>

 

Our module needs to be activated by creating file Boabaz_Shipping.xml in app/etc/modules directory:

<?xml version="1.0"?>
<config>
    <modules>
        <Baobaz_Shipping>
            <active>true</active>
            <codePool>local</codePool>
        </Baobaz_Shipping>
    </modules>
</config>

In new module create class Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate that will extend core magento class Mage_Shipping_Model_Mysql4_Carrier_Tablerate.

class Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate extends Mage_Shipping_Model_Mysql4_Carrier_Tablerate
{}

Then lets copy/paste getRate(Mage_Shipping_Model_Rate_Request $request) function from core class and change few last lines at the end of the function:

$select->where('condition_value<=?', $request->getData($conditionName));

$select->order('condition_value DESC');

to:

$select->where('condition_value>=?', $request->getData($conditionName));

$select->order('condition_value ASC');

That will make table rates conditions work in "up to" way.

8 comments on "How to use Magento Shipping Table Rates "

lili's picture
lili (visitor) - Sun, 03/01/2010 - 09:18:

Thank you very much for your effort in posting this information. Would really appreciate if you could elaborate a little bit for me on this:

""In new module create class Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate that will extend core magento class Mage_Shipping_Model_Mysql4_Carrier_Tablerate.""

and

""Then lets copy/paste getRate(Mage_Shipping_Model_Rate_Request $request) function from core class and change few last lines at the end of the function:""

I'm stuck at these two instructions...

1. Which is the 'new module'? config.xml?
2. What and where is 'core class'?

Thank you very much in advance if you could just point me in the general direction!

Cheers and Wishing you a very happy new year!

lili's picture
lili (visitor) - Sun, 03/01/2010 - 09:35:

HI,

i've solved the second question but i'm still stuck at the first...

Where do i paste this code?

""class Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate extends Mage_Shipping_Model_Mysql4_Carrier_Tablerate
{}""

Laurent Clouet's picture
Laurent Clouet - Mon, 04/01/2010 - 22:18:

Hi Lili,

Following code

class Baobaz_Shipping_Model_Mysql4_Carrier_Tablerate extends Mage_Shipping_Model_Mysql4_Carrier_Tablerate
{}

must be put in file app/code/local/Baobaz/Shipping/Model/Mysql4/Carrier/Tablerate.php

The new extension Shipping must be created. You can check this post "Developing module for Magento Tutorial - Where to Begin [Part 1]" for more details about creating new module.

lili's picture
lili (visitor) - Wed, 06/01/2010 - 18:06:

Thank you for your reply! Will check out the post... Thanks x 100!

Petralian's picture
Petralian (visitor) - Wed, 16/06/2010 - 14:13:

Hi Andrew,

Try this...

Country,Region/State,Zip/Postal Code,Order Subtotal (and above),Shipping Price
GBR,*,*,1,55
GBR,*,SS,399,0
GBR,*,*,999,0

Cheers ~

Keith's picture
Keith (visitor) - Tue, 31/08/2010 - 23:45:

Thank you. This was a last-minute save for me and works well.

Anonymous's picture
Anonymous (visitor) - Sun, 19/12/2010 - 12:19:

Could someone tell me where is the core class ?

Then lets copy/paste getRate(Mage_Shipping_Model_Rate_Request $request) function from core class and change few last lines at the end of the function:

Martijn's picture
Martijn (visitor) - Thu, 23/12/2010 - 15:17:

Just got this to work, thanks so much for posting.

It WAS a bit of a puzzle though.