Jump to content

Calculate Taxes After Subtracting Voucher Discount


Recommended Posts

I am running v.1.3.7 and have a United States based shop. I am looking for a way to alter the order of shopping cart calculations. Basically I need voucher discounts to be calculated and THEN have taxes applied to the discounted total.

For example, I have an item for $12.00 before taxes. I have a 25% off coupon to use. Shipping is $6.00. In the following example you can see that 5% state tax is applied to $12.00 instead of $9.00.

Sub-Total: $ 12.00
Total Coupons: -$ 3.00
Total shipping (tax excl.): $ 6.00
Total (tax excl.): $ 15.00
Tax (5% VA State Tax): $ 0.60
Total: $ 15.60

Prestashop should calculate it like the following:

Sub-Total: $ 12.00
Total Coupons: -$ 3.00
Total shipping (tax excl.): $ 6.00
Total (tax excl.): $ 15.00
Tax (5% VA State Tax): $ 0.45
Total: $ 15.45

I am not proficient in coding however I can follow any directions that you can provide. Any help would be much appreciated. Thank you in advance.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

I have the same problem. Does anyone know how to fix this problem? Basically we are paying too much tax and losing money on every sale. It will be an accounting nightmare to convince the government that we don't actually owe them what our records indicate we do.

Link to comment
Share on other sites

  • 2 weeks later...

This issue is in 1.4 and 1.41 as well. Just confirmed. I charge tax for Illinois orders...if I have a $15 voucher discount...and I'm not logged in as an Illinois user it correct discounts the amount of $15.

If I'm logged in as an Illinois user... I shows a discount of $14.02. I still can't determine where the 98 cents comes into play. (Total order subtotal-$115, $8 shipping, 7% tax).

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

I need this same fix too. If a customer has a voucher for $20, the voucher needs to be worth $20 before tax (see attached screenshot). If a customer enters a voucher code for $20 and the discount calculated is $17.86 they are not receiving their full discount.

Right now PS calculates the discount of the grand total (product total after tax). It should calculate the discount off the subtotal (product total before tax). This is a necessity for both Canada & USA.

Using PS 1.4.2.5

47128_e19ml4CZkfYrn5iu0Xk5_t

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 1 month later...
  • 3 weeks later...

I was able to fix this to how I wanted after making some changes in cart.php.

 

My code now calculates tax after the discounts are applied.

 

It's a dirty, brute force hacked fix but works for me until there is an official fix..

 

I can share what I did if anyone's interested..

Link to comment
Share on other sites

I was able to fix this to how I wanted after making some changes in cart.php.

 

My code now calculates tax after the discounts are applied.

 

It's a dirty, brute force hacked fix but works for me until there is an official fix..

 

I can share what I did if anyone's interested..

 

I would be interested in hearing what you did jadess. Thanks!

Link to comment
Share on other sites

Hello...

This is what I did.. (by the way, I'm using 1.4.5.1)

So in cart.php, there is a function getOrderTotal()

 

Within this function, there's this segment:

 

 foreach ($products AS $product) {
  if ($this->_taxCalculationMethod == PS_TAX_EXC) {
// Here taxes are computed only once the quantity has been applied to the product price
$price =	  Product::getPriceStatic((int)$product['id_product'],
 false, (int)$product['id_product_attribute'], 2, NULL, false, true, $product['cart_quantity'], false, (int)$this->id_customer ? (int)$this->id_customer : NULL,
 (int)$this->id, ($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));

$price = $product['price'];
$total_ecotax = $product['ecotax'] * (int)$product['cart_quantity'];
$total_price = $price * (int)$product['cart_quantity'];
if ($withTaxes)
{
$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);
 $total_ecotax = $total_ecotax * (1 + Tax::getProductEcotaxRate((int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) / 100);
 $total_price = Tools::ps_round($total_price + $total_ecotax, 2);
}
  }
  else {
$price = Product::getPriceStatic((int)($product['id_product']), true, (int)($product['id_product_attribute']), 2, NULL, false, true, $product['cart_quantity'], false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL));
$total_price = Tools::ps_round($price, 2) * (int)($product['cart_quantity']);
if (!$withTaxes)
 $total_price = Tools::ps_round($total_price / (1 + ((float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100)), 2);
  }
  $order_total += $total_price;
 }

 

I believe these particular line is what is calculating the taxes:

 

$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);

 

If you scroll further down, there is code that I believe figures the discount, so that is why I think it was being calculated before the discount was applied.

 

So first I commented out this line within getOrderTotal() (I also don't use ecotax)

$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);

 

Near the end of the function, there's some lines of code like this:

 

 if ($type == Cart::ONLY_SHIPPING) return $shipping_fees;
 if ($type == Cart::ONLY_WRAPPING) return $wrapping_fees;
 if ($type == Cart::BOTH) $order_total += $shipping_fees + $wrapping_fees;
 if ($order_total < 0 AND $type != Cart::ONLY_DISCOUNTS) return 0;
 if ($type == Cart::ONLY_DISCOUNTS AND isset($order_total_discount))

 

Directly before those lines, I added this:

 

  if ($withTaxes) {
  $order_total = $order_total *
  (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);  
  }

 

I'm still testing to make sure I haven't broken anything else but so far seems to work how I want it to...

Link to comment
Share on other sites

Hello...

This is what I did.. (by the way, I'm using 1.4.5.1)

So in cart.php, there is a function getOrderTotal()

 

Within this function, there's this segment:

 

 foreach ($products AS $product) {
  if ($this->_taxCalculationMethod == PS_TAX_EXC) {
// Here taxes are computed only once the quantity has been applied to the product price
$price =	  Product::getPriceStatic((int)$product['id_product'],
 false, (int)$product['id_product_attribute'], 2, NULL, false, true, $product['cart_quantity'], false, (int)$this->id_customer ? (int)$this->id_customer : NULL,
 (int)$this->id, ($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));

$price = $product['price'];
$total_ecotax = $product['ecotax'] * (int)$product['cart_quantity'];
$total_price = $price * (int)$product['cart_quantity'];
if ($withTaxes)
{
$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);
 $total_ecotax = $total_ecotax * (1 + Tax::getProductEcotaxRate((int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) / 100);
 $total_price = Tools::ps_round($total_price + $total_ecotax, 2);
}
  }
  else {
$price = Product::getPriceStatic((int)($product['id_product']), true, (int)($product['id_product_attribute']), 2, NULL, false, true, $product['cart_quantity'], false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL));
$total_price = Tools::ps_round($price, 2) * (int)($product['cart_quantity']);
if (!$withTaxes)
 $total_price = Tools::ps_round($total_price / (1 + ((float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100)), 2);
  }
  $order_total += $total_price;
 }

 

I believe these particular line is what is calculating the taxes:

 

$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);

 

If you scroll further down, there is code that I believe figures the discount, so that is why I think it was being calculated before the discount was applied.

 

So first I commented out this line within getOrderTotal() (I also don't use ecotax)

$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);

 

Near the end of the function, there's some lines of code like this:

 

 if ($type == Cart::ONLY_SHIPPING) return $shipping_fees;
 if ($type == Cart::ONLY_WRAPPING) return $wrapping_fees;
 if ($type == Cart::BOTH) $order_total += $shipping_fees + $wrapping_fees;
 if ($order_total < 0 AND $type != Cart::ONLY_DISCOUNTS) return 0;
 if ($type == Cart::ONLY_DISCOUNTS AND isset($order_total_discount))

 

Directly before those lines, I added this:

 

  if ($withTaxes) {
  $order_total = $order_total *
  (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);  
  }

 

I'm still testing to make sure I haven't broken anything else but so far seems to work how I want it to...

 

How do you comment this line, I don't see any changes?

 

$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Thanks. This seems to be working fine now! I also had to make this change in the 'getValue' function of Discount.php to work in Canada so the voucher value was NOT tax inclusive...

 

 

/* Absolute value */

case 2:

// An "absolute" voucher is available in one currency only

$currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent());

if ($this->id_currency != $currency->id)

return 0;

 

$taxDiscount = Cart::getTaxesAverageUsed((int)($cart->id));

if (!$useTax AND isset($taxDiscount) AND $taxDiscount != 1)

 

// COMMENTED OUT THE NEXT LINE AND INSERTED THE ONE AFTER

//$this->value = abs($this->value / (1 + $taxDiscount * 0.01));

$value = $this->value;

 

// Main return

Link to comment
Share on other sites

  • 6 months later...
  • 3 months later...
  • 2 months later...
  • 11 months later...
  • 4 months later...
  • 3 weeks later...
  • 2 years later...

Sorry for giving a live to this topic again but is there a fix for this? Because I have a store with PrestaShop™ 1.6.0.13 and the discount is being applied to the final price, I want the discount being applied to the product but without taxes...

 

So, in first place the discount must be applied to the total price of the products, and the taxes applies after the discount.

 

Is there a fix for this? A module? Anything? I really search to a solution for this but seems to be impossible...

 

Sorry for my english, i hope you understand.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...