Category based shipping in magento

One of the things that’s always annoyed me about Magento is the dearth of decent, free shipping modules available for the system. Out of the box you can do a reasonable amount with regards shipping, setting a flat rate or using one of the built in shipping methods…but if you want to do anything fancy (and in my experience, people always do) then you need to pay out for one of the many customisable shipping modules available.

It’s been nearly a year since I last looked at Magento, but a recent freelance project has meant me getting back into it and as the client has some very specific shipping requirements, I thought I’d write my own shipping module. I spent a few hours fiddling with config files, before rememebering why Magento always annoyed me so much (hint, it’s the config files) and used the rather brilliant magento module generator to get me started.

Here’s what I wanted from a shipping module:

  • Different shipping rates for individual products
  • Different shipping rates to different countries
  • Easy assigning of shipping rates to products

So, to tackle these problems I came up with a module that uses Shipping rules defined through categories. This means you can setup your rules, and then use the standard product / category concept in Magento to assign your shipping rates.

Once you install the module (see below for a download) each category gets a new attribute under its ‘general’ tab, named ‘Shipping’. That’s where you enter your rules. Rules are extremely simple, and consist of a series of lines, each of which is made up of ‘country code’ = ‘price’

here’s an example of one ruleset:

Capture

This translates to ‘If the delivery address is in the UK, free shipping. If it’s in the European union, shipping is 3.00, for the rest of the world it’s 5.00’.

You can have as many lines as you want (they’re processed top to bottom) and if you have multiple items in your basket that produce different shipping rates, the most expensive rate is picked (there’s no option to sum the rates together yet, I might add that in at some point).

You can add these rules to your actual, published product categories or do what I’ve done for this client and set up a seperate tree of ‘Shipping categories’ like so:

Capture

So there you go. Bit basic, but does what I needed it to do.

Here’s the download link (upload the ‘app’ folder from the archive into the root of your magento installation):




27 Comments

Just wanted to extend my thanks; this is exactly what I was looking for and couldn’t find as all the extensions on Magento Connect are way too complicated for what I needed. Excellent! Thank you!!

Hi Paul,
thanks for sharing your module, could you please tell me for which magento edition it is safe to use? I have CE 1.7 edition. Thanks again, Stavros

Hello & thanks for the help. Is there anyway to make this module do this:

I want only flat rate shipping per attribute set (or category). No matter the quantity of a certain attribute set (or category) is purchased, the flat rate applies as long as all items are of this certain attribute set (or from these certain categories). If items from different attribute sets (or categories) are also in the cart, then the shipping method defaults to the UPS (or other carrier) method.?

I say attribute set or category because in my case it doesn’t matter if I choose by attribute set or by categories, so either would work for me.

Thanks again!

Hi, can i use it for differets states, i need different shipping but only for one country, and some states.
Thanks

I run magento community 1.7.0.2

I offer free shipping on all products right now

I want to add a free sample in my store for which the customer only needs to pay the shipping amount. Table rates are not working.

Also when the customer is buying the regular products , the paid shipping option should not show up in checkout process.

Will your module help me with this problem ?

that looks great. Can you tell me how it interprets it when one product is in different category, say, I have a headphone in ‘Smartphones accessories’ and in ‘Computer accessories’. My shipping rules are
– 1.00 in ‘Smartphone accessories’
– 2.00 in ‘Computer accessories’

Hi. If you add if ($request->getFreeShipping() == true) { $rules_result = ‘0.00’; } on file app/code/local/Tallpaul/CategoryShipping/Model/Carrier/Categoryshipping.php the free shipping will start working with your module

Nice one Pablo. Just spotted your post..
Found i got errors with { $rules_result = ‘0.00’; } due to the .00
but ammended to { $rules_result = ‘0’;} and works great !

I think you have a minor error in collectRates:

I’ve added the second line to the following as $rules could be empty and it causes an error in the third line:

$rules = $category->getData(‘shipping’);
if ($rules == ”) {break;}
$rule_lines = explode(“\r\n”,$rules);

Btw, I’m trying to merge this with table rates. I’d really appreciate any help you might be able to give me with my question:

http://stackoverflow.com/questions/28652883/override-mage-shipping-model-resource-carrier-tablerate

Thanks for your extension which is really useful.
PedtoKTFC

Wondering if you ever managed to acheive this Pedro.
Im basically looking at implementing Paul’s module, but additionally offering free shipping on orders above £100 using table rates.
Any advice?
Best, Bob

Hi Bob, I can probably frig this for you in my module, I can take a look at it this evening.

In the continuining hackiness of this solution I’m envisioning adding rules like this:

GB+100=0
GB=5

ie: if country is GB and subtotal is greater than or equal to 100, shipping price is 0. if country is GB, shipping price is 5 etc etc.

Would that work for you?

Thanks for the speedy reply.
I implemented a shopping cart rule for the over £100 mark,
and followed Pablos suggestion above:
if ($request->getFreeShipping() == true) { $rules_result = ‘0’; }

And found this works a treat.
Though your solution could be better since the free shipping rules could apply differently to different catagories with ease.
Can you forsee any real problems using the simpler shopping rules and pablos additional code line?

Hi Paul,
great looking plugin you’ve built for magento shipping.
Looks like the ideal candidate for my needs..
The download link unfortunately no longer works, Any chance of a fresh link?

Thanks youuu!
Bob

Apologies.
Oddly, in wirting this response , the download link seems to have updated itself correctly!

nice one Paul, looking forward to having a good scope through the code, no doubt ill need to modify it slightly to my needs.

I know it’s several years since you posted this but in the case that you’re still following up comments..

In addition to setting shipping rates per item, a module that allows you to EXCLUDE certain items from certain countries is what I need. Does your extension allow you to do this ?

Hi Lydia, as you say I haven’t looked at this for a while, but if you use a price of ‘-1’ in one of your category rules, that should disallow shipping to that country.

If you want any help with this, or with magento in general I am available for contract work, you can email me at ‘[email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *