Rule to loop over products with one specific SKU in Drupal Commerce cart 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"
        }
      }
    ]
  }
}
Your real challenge appears to be this part of your question:


  ... put an if statement in the loop and look at whether the current line item has a specific SKU ...


Here is how to get that to work:


your Rules Loop is inside a Rules Action (of course).
but in a Rules Action you cannot use a Rules Condition ... except if you also use the Conditional Rules module, so that's what I'd recommend you to do to do what you're asking for. 
For an example using the Conditional Rules module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?". As an alternative to using the Conditional Rules module, you can also try to rework the relevant part of your Rules Actions into performing a Rules Component. Because in a Rules Component, it is possible to also add Rules Conditions. For more details on using Rules Components instead of Conditional Rules, refer to the answer to "What&#39;s the alternative to using the Conditional Rules module?".


Easy, no?

PS: I'm assuming this question is about D7 ...