Jump to content

[BUG] quantity discounts, TAX and Total error in the CART


Recommended Posts

I've find this big BUG.

If you add to cart a product with discount quantity, the taxes are calculate from the price without the discount.
For exemple:

Ipod 100€ (tax included), and for 10pz apply 50€ of discount to product (tax included??!?!?).
If I add 20 ipod in my cart, the total price of Ipods is (100€-50€)*20=1000€ (tax included)

In the cart I've this total report (tax 19.6%, prestashop 1.2.5 and 1.3.0.1):

The cart summary report:
Total products (tax incl.): 1 000,00 €
Total (tax excl.): 672,24 € WRONG!!! is calculed from prices without discount: 2000€ and not 1000€
Total tax: 327,76 € WRONG!!! is the tax of prices without discount. Calculaed from 2000€ and not 1000€
Total (tax incl.): 1 000,00 €

The amount of taxes is calculated without discount into account the quantity discount

19448_zXUxFTMXkEYLArqCdb5Y_t

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

I've found if you use the discount By Amount, the tax is calculated incorrectly as described above by luca.lb.
However, if you use By %, the tax appears to be calculated correctly.

So it is possible to offer discounts, just use the By %.

:ohh:

Link to comment
Share on other sites

  • 4 weeks later...
So it is possible to offer discounts, just use the By %.


Wont work because the discountmodule always rounding the amount...


There has to be a solution, can someone tell me how to do this?
I can't upgrade to 1.3 because I modded my prestashop too much, I think it will give some errors then...
Link to comment
Share on other sites

I have some great news for you!
Member Rocky had the solution!

Check it out below:

PrestaShop v1.3.1 includes security updates, so you really should upgrade, or at least apply the security fixes to your PrestaShop v1.2.5 installation.

I had a look at the bug report and luckily, Bruno explained how he fixed the problem. Try changing lines 1279-1281 of classes/Product.php from:

// Quantity discount
if ($quantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $quantity)))
   $price -= QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value);



to:

if (intval($id_cart))
// Quantity discount
{
   $totalQuantity = intval(Db::getInstance()->getValue('
       SELECT SUM(`quantity`)
       FROM `'._DB_PREFIX_.'cart_product`
       WHERE `id_product` = '.intval($id_product).' AND `id_cart` = '.intval($id_cart))
   ) + intval($quantity);
}
if ($quantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $quantity)))
{
   $discount_qty_price = QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value, $usetax, floatval($result['rate']));
   $price -= $discount_qty_price;
}



and lines 50-60 of classes/QuantityDiscount.php from:

public static function getValue($product_price, $id_discount_type, $value)
{
   if ($id_discount_type == 1)
   {
       $percentage = $value / 100;
       return $percentage * floatval($product_price);
   }
   elseif ($id_discount_type == 2)
       return $value;
   return 0;
}



to:

public static function getValue($product_price, $id_discount_type, $value, $usetax = true, $taxrate = 1)
{
   if ($id_discount_type == 1)
   {
       $percentage = $value / 100;
       return $percentage * floatval($product_price);        
   }
   elseif ($id_discount_type == 2)
       return !$usetax ? ($value / (1 + ($taxrate / 100))) : $value;
   return 0;
}

Link to comment
Share on other sites

×
×
  • Create New...