Jump to content

possible bug ? in product quantity discount in /classes/Product.php


ezakimak
 Share

Recommended Posts

Hi,
I am in the process of upgrading our shop (1.2.5) to the latest prestashop version, since I had made some modifications to the 1.2.5 Product.php file, I am comparing both files to include my changes to the new file provided with 1.3.1 version, I found this piece of code in Product::getPriceStatic that was not in the previous version

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


but it is not working in the way I think it should, for example if you have one product with combinations, the cuantity discount is applying if and only if the customer buys more than one item of the same combination, so if I have the same product in various colors and the customer chooses to buy one of each color he wont get the quantity discount it should have, so I changed the code to be like this

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))
   );
}
if ($totalQuantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $totalQuantity)))
{
   $discount_qty_price = QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value, $usetax, floatval($result['rate']));
   $price -= $discount_qty_price;
}



I would like to know if this is the desired intention of this piece of code, in my case it is not, so i changed it and I am sharing with you , perhaps other people are in the same situation as me

regards
Hugh

Share this post


Link to post
Share on other sites

Hi,
that is what I was trying to say, with the original code, prestashop is not doing the way you said it should. With the original code provided with 1.3.1 version, the same producut with different size or color are not computed in the same total for quantity discounts.

regards

Share this post


Link to post
Share on other sites

I've read more precisely your first post.

I'm perheaps wrong in what I was saying.
In BO, for sure, you can only define discount price per product not per product/combination.

Then, with this config, there are 2 ways of working in FO :
-- include different combination of the same product in the total, to apply the discount
-- count products of same combination to apply the discount

Both computation methods make sense.
I don't know what was the prestateam chose on the subject
Try on their demo or on a frsh install

Don't hesitate to post a feature evolution

Share this post


Link to post
Share on other sites

I tried the online demo,
For instance,

in the BO I configured Ipod shuffle to have these quantity discounts

* 2qty ---> 2 € ,

* 4qty ---> 4 €

then I placed an order in the FO this way

-- Ipod shuffle (color green ) 2 qty, it gave the 2 € discount
-- Ipod shuffle (color blue ) 2 qty , it gave the 2 € discount

but , as you can see, I bought 4 Ipod suffles in total.
From this I concluded that they chose the second option you mentioned in your previous post.
In my case , in our shop we needed to give the discount for the total quantity no matter the color or size as long as it is the same product.
I hope this will help other people in the same situation


regards

Hugh

Share this post


Link to post
Share on other sites

  • 5 months later...

Great!!! I have the same problem... and applied this solution in version 1.3.6.0:

       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 ($totalQuantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $totalQuantity)))
       {
           if (self::getTaxCalculationMethod($id_customer) == PS_TAX_EXC)
               $discount_qty_price = Tools::ps_round(QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value, $usetax, floatval($result['rate']), $currency), 2);
           else
               $discount_qty_price = QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value, $usetax, floatval($result['rate']), $currency);
           $price -= $discount_qty_price;
       }



Regards
Marco



Hi,
I am in the process of upgrading our shop (1.2.5) to the latest prestashop version, since I had made some modifications to the 1.2.5 Product.php file, I am comparing both files to include my changes to the new file provided with 1.3.1 version, I found this piece of code in Product::getPriceStatic that was not in the previous version
....
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;
       }
....


but it is not working in the way I think it should, for example if you have one product with combinations, the cuantity discount is applying if and only if the customer buys more than one item of the same combination, so if I have the same product in various colors and the customer chooses to buy one of each color he wont get the quantity discount it should have, so I changed the code to be like this

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))
   );
}
if ($totalQuantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $totalQuantity)))
{
   $discount_qty_price = QuantityDiscount::getValue($price, $qtyD->id_discount_type, $qtyD->value, $usetax, floatval($result['rate']));
   $price -= $discount_qty_price;
}



I would like to know if this is the desired intention of this piece of code, in my case it is not, so i changed it and I am sharing with you , perhaps other people are in the same situation as me

regards
Hugh

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More