I am using D7 and Drupal commerce, with a flat rate shipping service. In my country the VAT for both products and shipping costs must be included in the total VAT amount. But the only line items available in Rules are product line items. So in order for the VAT post to include the VAT for the shipping cost, I need the token:


... to also include the shipping service selected in the order. I have spent days trying to figure this out, with no luck. I have read this answer, but those suggestions does not work either. If I remove the filter that only shows product line items in the order summary view, the shipping shows in the table together with the products, which I do not want. And also the tokens still only reflected the product lines.

This is how I need it to look:

Product line item 1
Product line item 2
Product line item 3
   Net amount excl. VAT
   Shipping service
   VAT (including vat on products and on the shipping service)
   Total amount

Any help?

  • Once the question get an answer, its meaning cannot be changed.
    – apaderno
    Aug 7, 2019 at 10:18

1 Answer 1


If the data about a product are not available when processing a "line item", you can make them available. To do so, use a technique similar to what is explained in my answer to "How to access commerce_product field of line-items using Rules to flag the Commerce Product?", which includes a Rules Component that looks like so:

{ "rules_perform_an_action_on_a_selected_line_item" : {
    "LABEL" : "Perform an action on a selected line item",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "selected_line_item" : { "label" : "Selected Line Item", "type" : "commerce_line_item" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "selected-line-item" ], "field" : "commerce_product" } }
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "commerce_product",
            "id" : [ "selected-line-item:commerce-product:product-id" ]
          "PROVIDE" : { "entity_fetched" : { "product_fetched" : "Fetched Product" } }
      { "drupal_message" : { "message" : "Some details about this product: Product ID = [product-fetched:product-id], Product SKU = [product-fetched:sku], Product Title = [product-fetched:title], Product Creator = [product-fetched:creator]" } }

Here is a blueprint of what you need to do:

  1. Create a Rules Component, similar to the above Rules Component. Just an import of that Rules Component should be enough (to get started and further improve it as detailed below).
  2. Rework the Drupal Message shown via the last Rules Action in the Rules Component (Starting with "Some details about this product"), by also using any of the available tokens that you're interested in.
  3. Execute that Rules Component inside your Rules Loop of the rule in which you want to loop over all line items.
  4. Improve the Rules Component from Step 1 by creating whatever additional Rules Action(s) you need. Make sure to place these Rules Action(s) AFTER that Rules Action (in the Rules Component) that performs "Fetch entity by ID".
  • Pierre.Vriens: Thanks a lot and upvote! I will try to implement this method.
    – TBJ
    Aug 8, 2019 at 8:34

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