2

The default sales tax Component Rule calculates sales tax on all line items... so it was (for us) correctly adding sales tax to products and shipping line items. We started using Userpoints_Discount and I created a new Product Type 'Points' to allow users to purchase Userpoints. I then edited the Component Rule as below. So now, it calculates Sales Tax on the product which are NOT 'Points' (good) but it has stopped calculating sales tax on shipping (bad).

Can someone look at this Component Rule and explain why the Shipping Line Item is no longer having sales tax calculated?

The logic should be:

IF Commerce Line Item IS IN bundle Products OR bundle Shipping  
  AND Commerce Line Item Product Type IS NOT 'Points'

I am using Commerce Kickstart 2.

{ "commerce_tax_rate_state_of_washington" : {
    "LABEL" : "Calculate State Of Washington 9.5%",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Tax", "sales_tax" ],
    "REQUIRES" : [ "rules", "inline_conditions", "commerce_tax" ],
    "USES VARIABLES" : { "commerce_line_item" : { "label" : "Line item", "type" : "commerce_line_item" } },
    "IF" : [
      { "AND" : [
          { "entity_is_of_bundle" : {
              "entity" : [ "commerce-line-item" ],
              "type" : "commerce_line_item",
              "bundle" : { "value" : { "product" : "product", "shipping" : "shipping" } }
            }
          },
          { "NOT commerce_product_has_type" : { "commerce_line_item" : [ "commerce_line_item" ], "type" : "points" } }
        ]
      }
    ],
    "DO" : [
      { "commerce_tax_rate_apply" : {
          "USING" : {
            "commerce_line_item" : [ "commerce-line-item" ],
            "tax_rate_name" : "state_of_washington"
          },
          "PROVIDE" : { "applied_tax" : { "applied_tax" : "Applied tax" } }
        }
      }
    ]
  }
}
1

NB: As so often happens with Drupal, apparently I was asking the wrong question. IMO this is such a -basic- part of any eCommerce system used in USA/Canada, but the answer is buried in a support request on Drupal.org. This is -terrible- documentation and I hope the Commerce Guys are duly ashamed. Doesn't matter how cool the code is if one can't easily figure it out.

Apparently what one has to do is add the rule into

Admin -> Store Settings -> Shipping (Calculation Rules) -> Configure Component

Please see here (#29) https://www.drupal.org/node/1243218#comment-6732098

...and also (#42).

What one does is add a new Rule to Shipping Event: Calculate Shipping Condition: Order Address Component Comparison Actions: (Your Salestax Component Rule goes here)

For the Action you simply use the same sales tax component rule you used for

Admin -> Taxes -> Configure Component

...in my case 'Sales Tax WA'

So I suppose if you live in a jurisdiction with many possible taxes, you'd create a separate component rule for each under shipping, using exactly the same Order Address Comparison and Action Rule you used for the Taxes section.

What confused -me- was that I thought one could use use the IF/AND/OR under Taxes to differentiate between Shipping and Product line items. Apparently this does not work. That would be a MUCH better solution (reduce duplication of effort, cut down on errors.) If someone knows how to do this, PLEASE post here!

So, in one sentence, you have to apply all the same sales tax component rules in two places: in Taxes (for product line items) and then in Shipping under Calculate Rules to apply tax to the freight.

And here is the exported rule:

{ "rules_apply_taxes_to_shipping" : {
"LABEL" : "Apply Taxes to Shipping",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "commerce_order", "rules", "commerce_shipping" ],
"ON" : { "commerce_shipping_calculate_rate" : [] },
"IF" : [
  { "commerce_order_compare_address" : {
      "commerce_order" : [ "commerce-line-item:order" ],
      "address_field" : "commerce_customer_billing|commerce_customer_address",
      "address_component" : "administrative_area",
      "value" : "WA"
     }
   }
 ],
 "DO" : [
   { "component_commerce_tax_rate_state_of_washington" : { "commerce_line_item" :
     [  "commerce-line-item" ] } }
       ]
   }
}
  • FWIW your question was a little opaque if that was your solution. I agree that it's super annoying that the solution to get the tax rate applied to the entire order is applying the tax both to the order and the again as a shipping calculation. Would make much more sense to apply the tax once to the order total with shipping. – nizz0k Dec 6 '15 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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