I have tried to use the Commerce Remove Tax Module with the Product Pricing Rule based on the "payment method comparison" which should remove any tax if payment method is not "paypal", but it does not seem to remove the tax.

This is odd because my previous attempt to apply checkout based tax/fee via Product Pricing Rule based on the "payment method comparison" added the fee after the paypal transaction was processed. This obviously did not work so well since it left all of my orders with a remaining balance equal to the tax/fee applied.

Has anyone used this module successfully? Any tips?

Comments

fugazi’s picture

same problem. After installation of the module, the VAT is still displayed. See screenshot.

screenshot 1

Screenshot 2

Do I have the rule might have done wrong.

{ "rules_mehrwertsteuer_bei_bestellungen_aus_nicht_eu_l_ndern_entfe" : {
    "LABEL" : "Mehrwertsteuer bei Bestellungen aus Nicht-EU-L\u00e4ndern entfernen",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_remove_tax", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "commerce_order_compare_address" : {
          "commerce_order" : [ "commerce_order" ],
          "address_field" : "commerce_customer_billing|commerce_customer_address",
          "address_component" : "country",
          "value" : "CH"
        }
      }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "commerce_remove_tax" : { "commerce_line_item" : [ "list-item" ], "increase_base_price" : 0 } }
          ]
        }
      }
    ]
  }
}
twardnw’s picture

Not working for me as well. Here's my rule export:

{ "rules_remove_tax" : {
    "LABEL" : "remove_tax",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_remove_tax", "commerce_rules_extra" ],
    "ON" : { "process_checkout_pane" : [] },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "commerce-order" ], "type" : "commerce_order" } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "commerce_remove_tax" : { "commerce_line_item" : [ "list-item" ], "increase_base_price" : 0 } },
            { "drupal_message" : { "message" : "tax trigger: [commerce-order:field_tax_exempt_code]" } }
          ]
        }
      }
    ]
  }
}
Drupal Bros’s picture

Hi guys - not sure whether you got this working but here is my analysis (FULL DISCLOSURE: Drupal n00b here).

1) I believe you need to put the rule on the "Calculating the sell price of a product" Event.

2) Assuming you update your Rule as per 1) above, in fugazi's case, since 99% of users will not be logged in nor have a billing/shipping address pre-set to CH the regular prices displayed (eg while shopping) will all be VAT inclusive. Then when the user enters address details the prices will update. This may appear to be working, but I believe if the user were then to return to shopping they would start to see tax-removed prices.

If I am correct on the above then there are two issues worth addressing, namely a) we need some documentation for this module, and b) is the above considered "correct" functionality?

I would prefer to see tax removed only at the final step (possibly with a "tax removed" line item).

My code below which would ideally remove taxes once the shipping address is confirmed to be NOT AU does not work, I believe because for the majority of visitors to the site have nothing set for shipping address when they first arrive on the site. The option for me is to do the reverse (ie Condition "is one of" and then list ALL country codes except AU) but this too will break if the visitor sets their shipping address to a non-AU value then goes back and continues shopping.

{ "commerce_tax_remove_tax" : {
    "LABEL" : "Remove Tax",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Tax" ],
    "REQUIRES" : [ "commerce_order", "commerce_tax", "commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "NOT commerce_order_compare_address" : {
          "commerce_order" : [ "commerce-line-item:order" ],
          "address_field" : "commerce_customer_shipping|commerce_customer_address",
          "address_component" : "country",
          "value" : "AU"
        }
      }
    ],
    "DO" : [
      { "commerce_tax_remove_taxes" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "increase_base_price" : 0,
          "tax_rates" : { "value" : { "gst" : "gst" } }
        }
      }
    ]
  }
}
pyry_p’s picture

Due to lack of documentation I assumed your supposed to remove the taxes at somepoint within order. Then I thought that that for some reason taxes get recalculated at various phases because some weight issues. So when calculating taxes I just injected the same conditions in reverse to prevent that when order has a shipping address country. It seems to work, but need to test more.

#3 Drupal Bros
1) I concure.
I was wrong.2) I think that might not be such a disaster. If the removing taxes has conditions that the product(line-item?) has an order and that order has shipping address country outside region. Then the taxes should (and seem to) still remain included while viewing product-variation(not line-item yet) outside the cart(order).

Mayby there should be some kind of notification that taxes on the order are removed due to information provided by the customer.

*warning there seems to be unhandled exception in rules where looping over items in "calculating sell price of a product" causes error at admin/configuration/payments page. Placing the loop in component prevented the error.

Drupal Bros’s picture

To be honest I never ended up using this as a solution as it was too clumsy out-of-the-box, but I'd be interested to hear how exactly you did this:

So when calculating taxes I just injected the same conditions in reverse to prevent that when order has a shipping address country.

jonas139’s picture

Hi guys,

I have customized the rule and action a little bit and now it works for me.
Here is my rule export:

{ "rules_calculate_tax" : {
    "LABEL" : "Your Label",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "YourTag" ],
    "REQUIRES" : ["commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "DO" : [
      { "my_module_calculate_vat" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "increase_base_price" : 0
        }
      }
    ]
  }
}

with the only change to the action is this line:

  // Remove it from the components array.
      unset($price['data']['components'][$key]);

to

// Set price to 0
 $price['data']['components'][$key]['price']['amount'] = 0;

Now the tax is still in the components array but you can unset with this hook:

/**
 * @param $components
 * @param $price
 * @param $entity
 *
 * Implements hook_commerce_price_formatted_components_alter().
 */
function hook_commerce_price_formatted_components_alter(&$components, $price, $entity) {

 // If tax rate is 0, unset it from the view
  $tax_rates = commerce_tax_rate_titles();
  foreach ($components as $component_name => $component){
    // Check if the component is a tax rate and remove the 'tax|' prefix
    if (strpos($component_name,'tax|') !== FALSE){
      $component_name_without_prefix = str_replace('tax|','',$component_name);

      // If the component name is in the tax rate array and the amount is 0, unset it from the components
      if (array_key_exists($component_name_without_prefix,$tax_rates) && $component['price']['amount'] == floatval(0)){
        // Remove the component from the components array
        unset($components[$component_name]);
      }
    }
  }

That worked for me!