Discussions

shipping prices depending on weights

Greetings, I have a question...

I have a product type to which I added a list field for choosing the weight of the product...
a) I need to make the shipping prices depending on those weights
b) when the weight of a product goes over the specific weight I must inform the customer that we will email him the information about the shipping price so that he could pay only after that
Does anyone have any idea how to make any of these two things?

thnx

Posted: Sep 17, 2011

Comments

MarkoC on September 21, 2011

The thing under b) I managed to solve.
I'm not sure if this is the best way, but...

I've made a module that adds a checkout rules.
That is, I rearranged commerce_order_rules_contains_product(in its own new module)
in which I hardcoded the logic for my weight fields in products.

I hope that I will find some more elegant solution for problem a)

Fonant on January 19, 2013

I've found a way to calculated shipping rules by total order weight, and to enable different calculations for different weight ranges. They key part of the solution was to make use of the conditional rules module (http://drupal.org/project/rules_conditional) to allow tests to occur within Actions.

So my Rule's actions look a bit like this (in shorthand). First we calculate the total weight, using conditions to get the required variables into scope:

Add a variable, decimal value, total-weight
Loop
  Conditional
    If: Data comparison list-item:type = Product
      Conditional
        If: Entity has field: field_packed_weight
          Calculate a value: weight * quantity => item-weight
          Calculate a value: total-weight + item-weight => new-total-weight
          Set a data value: total-weight = new-total-weight

So we now have our variable total-weight :) This can be output using the Debug value action, if the Devel module is enabled.

Then we can use the total weight to decide which calculation to use, and to set the supplied shipping line item's value. In my case the switch was at 2kg:

Conditional
  If: Data comparison total-weight is-lower-than 2000
    Calculate a value: weight * factor1 => weight-cost
    Calculate a value: weight-cost + fixed-cost1 => total-cost
    Set the unit price to a specific amount: commerce-line-item total-cost <shipping type>
  Else:
    Calculate a value: weight * factor2 => weight-cost
    Calculate a value: weight-cost + fixed-cost2 => total-cost
    Set the unit price to a specific amount: commerce-line-item total-cost <postage type>

hiyabeh on November 17, 2013

Hello Fonant,

I finally found your post after trying for the entire weekend, wow!! I am feeling excited again.

I tried every step as you listed here but something is stopping me from getting the new-total-weight result. Could it be something that has to do with devel module?? I dont quite understand what you meant by " This can be output using the Debug value action, if the Devel module is enabled." Would you mind spending a few minutes to explain that a little further? also, did you use any calculation rules in commerce or rule components at all?

Thanks so much I hope you will see this reply soon.

BB