I'm still a novice at Rules. I'm using Drupal Commerce and have the Flat Rate shipping service enabled. I'm using Rules to calculate a surcharge to the flat rate based on the number of items in the shopping cart. So far this rule works.
However, I now want to modify the rule so that it only calculates the surcharge based on the number of products with a specific SKU. All other line items in the cart, which may be other products, should be ignored for the purposes of this calculation.
If I was just coding this, I would put an if statement in the loop and look at whether the current line item has a specific SKU. But I totally don't understand how to do that with Rules.
Thanks for any help.
Here is my current rule:
{ "rules_createspace_flat_rate_calculator_expedited_" : {
"LABEL" : "CreateSpace Flat Rate Calculator (Expedited - US)",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "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" : "ship_manuals_to_you_expedited_"
}
},
{ "commerce_order_compare_address" : {
"commerce_order" : [ "commerce-line-item:order" ],
"address_field" : "commerce_customer_shipping|commerce_customer_address",
"address_component" : "country",
"value" : "US"
}
}
],
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "commerce-line-item:order:commerce-line-items" ] },
"ITEM" : { "order_line_items" : "Order line items" },
"DO" : [
{ "data_calc" : {
"USING" : {
"input_1" : [ "order-line-items:quantity" ],
"op" : "*",
"input_2" : "250"
},
"PROVIDE" : { "result" : { "shipping_volume_surcharge" : "Shipping Volume Surcharge" } }
}
},
{ "commerce_line_item_unit_price_add" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : [ "shipping-volume-surcharge" ],
"component_name" : "flat_rate_ship_manuals_to_you_expedited_",
"round_mode" : "1"
}
}
]
}
},
{ "commerce_line_item_unit_price_add" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : "1000",
"component_name" : "flat_rate_ship_manuals_to_you_expedited_",
"round_mode" : "1"
}
}
]
}
}