I've been trying to create a module that will slot into commerce shipping to allow the shop to create weight based shipping. I ultimately want to be able to do these things:

total weight x price per kilo = shipping cost
band based pricing eg 0-10kg = 1 11-20kg = 2

So far I am working on the top one and I have made a module that creates a rule as well as creates a weight field on the product types so products can be assigned weights. How do I get access to this weight data in my shipping module? I can only seem to find ways to get the order total price.

CommentFileSizeAuthor
#17 weight_shipping.zip4.94 KBDaemon_Byte

Comments

googletorp’s picture

Status: Active » Fixed

The order has reference to line items which has reference to products.

So line item quantity x product weight summed for all line items should give total weight.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Daemon_Byte’s picture

Status: Closed (fixed) » Active

Hi again. I managed to make a weight based shipping module and now I expanded it so it can handle different rates for different areas. Hopefully I will finish the project soon and get some of the code cleaned up for being released. The one thing I have noticed now is when they change the country on the checkout/3 page the shipping options area doesn't change. Instead they have to click continue then back which will change the postage option list. Then they have to click continue again for it to be applied to the price. Is this a rules trigger I have wrong or is this bit of ajax just missing and in need of coding?

googletorp’s picture

I believe this issue is being addressed in Ryan's work in the 2.x branch.

Daemon_Byte’s picture

arh I see so it's a known issue? I will see if I can find some more info about it so I can get it fixed :)

Daemon_Byte’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

I've been playing around with 2.x since if I'm going to make this work I might as well put the effort into the latest one. Since it has changed so much I've struggled to edit my module to fit. Before I made fields on the rule that allowed you to set your own rate for each rule. How do I put a field on the calculation rule so I can put in a rate specific to that rule?

BenK’s picture

Subscribing

minneapolisdan’s picture

+1, I probably will need a shipping module like this at some point

Daemon_Byte’s picture

I couldn't figure out a way to get it to work with rules properly but I had an idea of sorts so when I get something working I'll post it here along with my failed rules attempt and maybe someone who knows best can decide which approach to take going forward.

Anonymous’s picture

+1!

Daemon_Byte’s picture

Hey Googletorp, I switched to the 2.x branch and I have managed to get a system created where you can create rules based on weight and country. It picks the right weight out and everything but once again I am stuck with the inability for the page to refresh when you change the country without clicking next and back. http://shop.styalways.co.uk/checkout/13 (username: test / password: testpassword) It's still a development site but it gives you an idea. A UK address should do 10, EU address 20 and anything else 30.

Can you give me any pointers in where I can find the code I need to get that radio option to update and therefore update the shipping line at the top? Also is it possible to add multiple entries into those radio buttons with just 1 shipping module?

googletorp’s picture

#11 Ryan have made the 2.x branch, I haven't looked much into it yet, so he's your best bet for help/guidance.

dpolant’s picture

I took a stab at this before I found this thread ... http://drupal.org/sandbox/dpolant/1330738

This module uses a configuration page rather than rules to set different rates for different product types. Feel free to use or fork this project if it will help, although I didn't write anything in to deal with countries.

Daemon_Byte’s picture

I ended up making a separate configuration page as well. Did you manage to get the prices to change on the checkout form when you change country? I will certainly have a look at yours and see if I can use it to fix the flaws in mine :)

jimkont’s picture

Hi,

I needed a fixed shipping price per weight range module, so I used [#13] 's work to create a new rule.

Now using my module and flat rate shipping I can create shipping rules depending on the total order weight
the code is in github (in case anyone cares)
https://github.com/jimkont/drupal-commerce-order-weight-rule

Best,
Dimtiris

ardnet’s picture

Subscribe

Daemon_Byte’s picture

StatusFileSize
new4.94 KB

I have attached my version of the weight based shipping module. So far it seems to work rather well but I do need some help with the following issues:

1) I think it could be made cleaner with the way it interacts with commerce module

2) It currently hides the summary table on the checkout page because when you change the country the shipping doesn't change. I could use some help making that happen.

googletorp’s picture

Status: Active » Closed (works as designed)

Maybe you should create a sandbox Deamon_Byte and take the discussion there.

Some pointers:

Looks like weight_shipping_create_instance is missing
You should use Commerce Physical Product to handle storing the weight.
Doing queries on serialized data isn't a good idea, it isn't database agnostic and can easily break.
You haven't use t() a lot of places.
currency_code for the rates is hardcoded

In any rate this issue doesn't really belong here anymore. This is talk about making a new module, more than it is anything related to commerce shipping.