Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I made shipping $5 and $1 for every item added (so I set base shipping to $4). I followed this tutorial at https://commerceguys.com/blog/using-calculation-rules-add-item-shipping-...
Here is my rule:
{ "rules_add_1_to_each_item_for_shipping" : {
"LABEL" : "Add $1 to each item for shipping",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_shipping" ],
"ON" : { "commerce_shipping_calculate_rate" : [] },
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "commerce-line-item:order:commerce-line-items" ] },
"ITEM" : { "line_item" : "Line Item" },
"DO" : [
{ "data_calc" : {
"USING" : { "input_1" : [ "line-item:quantity" ], "op" : "*", "input_2" : "100" },
"PROVIDE" : { "result" : { "calculated_line_item_shipping" : "Calculated Line Item Shipping" } }
}
},
{ "commerce_line_item_unit_price_add" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : [ "calculated-line-item-shipping" ],
"component_name" : "flat_rate_standard_shipping",
"round_mode" : "1"
}
}
]
}
}
]
}
}
Shipping was calculated correctly before Coupon. I did noticed that whenever I added a coupon the shipping went up by $1 incorrectly! I believe this is because the rule I created counts line-items. I believe this is because coupons are added as line-items in actions unlike tax and shipping.
Comment | File | Size | Author |
---|---|---|---|
without coupon.png | 27.93 KB | stephenevans | |
with coupon.png | 33.57 KB | stephenevans |
Comments
Comment #1
stephenevans CreditAttribution: stephenevans commented