1

I'm having trouble finding a solution for combining location & weight-based shipping with drupal commerce.

I need to have three shipping zones (DK, EU, ROW) with individually priced weight steps inside each zone (0-500g, 500-1000g, 1000-2000g, 2000-5000g).

I've gone through a bunch of tutorials and looked at other forums where people have similar requests. But haven't found a solution yet - which should be possible for such a 'simple' problem, right?

To sum up I need advice on how to configure the following shipping calculation rules:

  • Free Shipping (no weight)
  • DK Shipping (1-500g)
  • DK Shipping (501-1000g)
  • DK Shipping (1001-2000g)
  • DK Shipping (2000-5000g)
  • EU Shipping (1-500g)
  • EU Shipping (501-1000g)
  • EU Shipping (1001-2000g)
  • EU Shipping (2000-5000g)
  • ROW Shipping (1-500g)
  • ROW Shipping (501-1000g)
  • ROW Shipping (1001-2000g)
  • ROW Shipping (2000-5000g)

I can't figure out how to check for a line item's weight in a rule?

I've got Shipping, Flat Rate, Physical Product, Physical Fields and Rules Extra enabled.

2 Answers 2

3

I ended up doing 12 rules as @nvahalik suggested. Here's an export of one of them. Doing the others is just a matter of cloning this rule and changing weight, territories and shipping price accordingly

{ "rules_dk_shipping_1_499g" : {
    "LABEL" : "DK shipping (1-499g)",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Checkout", "Commerce Payment" ],
    "REQUIRES" : [
      "rules",
      "commerce_physical",
      "commerce_order",
      "commerce_line_item",
      "commerce_shipping"
    ],
    "ON" : { "commerce_shipping_calculate_rate" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-line-item:type" ], "value" : "shipping" } },
      { "data_is" : {
          "data" : [ "commerce-line-item:commerce-shipping-service" ],
          "value" : "by_weight"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:order" ],
          "field" : "commerce_customer_shipping"
        }
      },
      { "commerce_physical_rules_order_weight_comparison" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "operator" : "\u003E=",
          "value" : "1",
          "unit" : "g"
        }
      },
      { "commerce_physical_rules_order_weight_comparison" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "operator" : "\u003C",
          "value" : "500",
          "unit" : "g"
        }
      },
      { "commerce_order_compare_address" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "address_field" : "commerce_customer_shipping|commerce_customer_address",
          "address_component" : "country",
          "operator" : "is one of",
          "value" : "DK"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_amount" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : "3300",
          "component_name" : "shipping",
          "round_mode" : "0"
        }
      }
    ]
  }
}
3
  • Looks good. Glad you got it figured out.
    – nvahalik
    Commented Nov 2, 2015 at 14:48
  • thanks Kristoffer for the export from your rules but i would like to put the same configuration for a drupal commerce website, mixing weight and location calculating shipping from a total cart. As a newbee, could you please help me with a tutorial explaining how you have configurate your shipping total cost based on different weight and locations. Thanks
    – Olivier
    Commented Jul 18, 2016 at 14:20
  • It's actually in the rules too. Look at the amount lines. Those are the prices in Danish kroners. Makes sense? Commented Jul 18, 2016 at 14:27
1

This would be doable with 12 individual rules (3 countries x 4 sizes = 12 rules). You can also try this module: Commerce shipping Province weight.

Shipping is one of the few areas where Commerce tends towards more customized solutions. But perhaps that one will help you.

2
  • Thanks a lot @nvahalik. I'd prefer the Rules solution to avoid installing yet another module and to avoid a lot of configurations. I've elaborated my question with some specific issues with my rules-knowledge. Hope you've got time to take a look. Commented Nov 2, 2015 at 3:00
  • Wait, nailed it I think - will test and provide my solution here when it's tested Commented Nov 2, 2015 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.