xxxxxxxxxxxxxxxxxxxx Posted May 21, 2014 Share Posted May 21, 2014 (edited) I need the option to apply different tax rates (22%, 10% and 4%) to the same product, based on which group the customer is into. So for example: - user from group A will be able to buy all my products with vat at 22% - user from group B will be able to buy all my products with vat at 10% - user from group C will be able to buy all my products with vat at 4% Is it possible? How can I achieve this? I can't find any addon with this feature, do I have to get my hands dirty with php? Any suggestion on where to look will be appreciated. Thanks! Stefano Edited May 21, 2014 by stefanoginella (see edit history) Link to comment Share on other sites More sharing options...
xxxxxxxxxxxxxxxxxxxx Posted May 21, 2014 Author Share Posted May 21, 2014 I've tried to copy the file classes/tax/Tax.php here override/classes/tax/Tax.phpand then I've editet this function: public static function getProductTaxRate($id_product, $id_address = null, Context $context = null) { if ($context == null) $context = Context::getContext(); $address = Address::initialize($id_address); $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct($id_product, $context); $tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules); $tax_calculator = $tax_manager->getTaxCalculator(); return $tax_calculator->getTotalRate(); } into this one public static function getProductTaxRate($id_product, $id_address = null, Context $context = null) { if ($context == null) $context = Context::getContext(); $address = Address::initialize($id_address); $groups = Customer::getGroupsStatic((int)($address->id_customer)); $taxratenew = null; foreach ($groups as $g) { if ($g <= 4) { //set the group you want here ( '>;' or '=') $taxratenew = 1; //set the tax rate you want here (e.g. "0") } else if ($g == 5) { //set the group you want here ( '>;' or '=') $taxratenew = 2; //set the tax rate you want here (e.g. "0") } else if ($g == 6) { //set the group you want here ( '>;' or '=') $taxratenew = 4; //set the tax rate you want here (e.g. "0") } } if (!$taxratenew) { $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct($id_product, $context); $tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules); $tax_calculator = $tax_manager->getTaxCalculator(); $taxratenew = 22; } return $taxratenew; } The problem is that $g, which contains the returned value of Customer::getGroupsStatic((int)($address->id_customer)); is always 1... What am I doing wrong? What's the proper method to get the user's group id? Thanks! Link to comment Share on other sites More sharing options...
xxxxxxxxxxxxxxxxxxxx Posted May 22, 2014 Author Share Posted May 22, 2014 I fixed the problem, now the working function is this one and each group has its own tax rate (but if I want to edit it I need to edit the code, because the tax rates set in the admin panel are basically ignored) public static function getProductTaxRate($id_product, $id_address = null, Context $context = null) { if ($context == null) $context = Context::getContext(); $groups = Customer::getGroupsStatic($context->cart->id_customer); $taxratenew = null; foreach ($groups as $g) { switch ($g) { case 1: case 2: case 3: case 4: $taxratenew = 22; break; case 5: $taxratenew = 10; break; case 6: $taxratenew = 4; break; default: $taxratenew = 10; } } if (!$taxratenew) { $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct($id_product, $context); $tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules); $tax_calculator = $tax_manager->getTaxCalculator(); $taxratenew = $tax_calculator->getTotalRate(); } return $taxratenew; } 2 Link to comment Share on other sites More sharing options...
SublimeVizion Posted February 3, 2015 Share Posted February 3, 2015 Hi. First off thank you very much for this code. It works awesome except i noticed that sometimes paypal won't include the wholesale tax. It's funny but it's usually when i have 3 items in the shopping cart. If i have 2 or 4 items paypal will show and include the tax. Any ideas??? Link to comment Share on other sites More sharing options...
codei Posted May 13, 2015 Share Posted May 13, 2015 Thanks -stefanoginella. That works but Im having a problem: I want my shipping to be taxed and it's still taxed even when I use your code to set the product tax to 0. I changed the function getCarrierTaxRate to emulate it but it looks like that function isn't even used in the tax.php or anywhere else in the code. Any suggestions on how to accomplish this? Link to comment Share on other sites More sharing options...
panamahatpub Posted May 31, 2015 Share Posted May 31, 2015 I tried this on PS 1.6.0.14, and it was not working for me. For debugging I even set $taxratenew = (float)0; right before the return just to test, and it still calculated tax in the cart! I tried in both override/classes/tax/Tax.php and I tried modifying directly classes/tax/Tax.php just to rule out any override problems. Same thing - customers always have tax. Link to comment Share on other sites More sharing options...
rcho Posted October 28, 2015 Share Posted October 28, 2015 I also tried these changes on PS 1.6.1.1 and it is not working as well. My experience is very similar to the user above. The changes seem to have no effect on the tax rate charged to the customer. Anyone else try these changes on 1.6.1.1? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now