Jump to content

[SOLVED] Tax-bug with Quantity discount in 1.2.5


Recommended Posts

People,

I have 1.2.5 and I modified it for various reasons.
The problem is that 1.2.5 has a bug.

When you use quantity discount along with the standard tax, the pricecalculation is not correct.

The tax is being calculated on the total price without discount, instead of total price with discount.


If anybody knows how to solve this without upgrading; feel free to reply!!

Prestashop solved the problem in version 1.3, but since I've modfied it, I'm afraid that I ruin my prestashop, and can start over again...
So question: can I just update the part of the quantity-discount, and leave the rest?
And if so, which part do I take?

If someone can help, it would be great!

(ps: sorry for the bad-English)

Link to comment
Share on other sites

Thing is, you can backup your instalation and check for yourself by trial end error if and what works. But i would just upgrade, it'll be faster and more profitable on the long run. Do a test with 1.3.1, install it on a subdomain, import the database, copy your theme and modules, run the sql updates from the install directory and see if it works.

Link to comment
Share on other sites

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

Rocky, you are a hero!
It worked as a charm, the pricecalculation is now correct!

BUT...
I do have another problem.
When I first had the taxproblem, I tried switching my taxes off/on and see what would happen.
After that, the quantity discount will only work with percent instead of fixed amount.
I can fill in the fixed amount, but the system automatically makes it percent instead of fixed amount!

So when I trie fill in 10 euros, it will actually show the price at the quantity discount tab with 10 PERCENT off...

Also the prices of related products below the product selected are shown tax-INCLUSIVE!

Would be great if you know the solution for this too!

If you don't, you are still a hero!

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...