Jump to content
tomerg3

[MOD] Quantity Discounts on all attributes

Recommended Posts

I've seen many people request it, so here it is....

With this mod, the Quantity Discount will be calculated per product, regardless of the attributes.

Example: iPod Shuffle Quantity 10 = 10% discount

Add to cart 5 blue ones and 5 green ones and you'll get the discount.

I have not done a lot of testing on it, so please let me know if you find any bugs.

There are 2 files in the classes folder that need changing, I included them for V1.2 and 1.3 (make sure to backup your current files).

V2 released - CRITICAL UPDATE!

The cart id which is used to calculate the quantity discount was used from $cookie and when a payment module confirms an order $cookie is empty, resulting in a payment error (since PS is expecting the full price).

The code was changed so it doesn't use $cookie in the order validation.

quantity_discounts_with_attributes.V2.zip

Share this post


Link to post
Share on other sites

Tomer, Thank u so much, u made my day. After quick testing it works great! i'll work some more on it during the weekend and let u know. Have a nice weekend yourself

Share this post


Link to post
Share on other sites

Is there a way to get quantity discounts regardless of attributes?
Example: add any 3 items to the cart at the standard price; add 1 more item and receive a 10% discount instantly on all items in the cart; add 5 more various items [in addition to the 4 existing items] and receive an additional 15% discount on all 9 items; and so on ... The items need not be related by any category or attribute.
Is this doable?
Thanks
Old Ken

Share this post


Link to post
Share on other sites
I have not done a lot of testing on it, so please let me know if you find any bugs.


Hi,
I didn't find a bug for the time, I've just read your 2 files for the v 1.3 (Product class and PaymentModule.php) and I had some questions :
- Product.php :
               // Get quantity including attributes //
       $qty_result = Db::getInstance()->ExecuteS('SELECT SUM(quantity) AS sum FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.intval($cookie->id_cart).' AND `id_product` = '.intval($id_product));
       $real_quantity = $qty_result[0]['sum'];


It could be write like :

// Get quantity including attributes //
       $real_quantity = intval(Db::getInstance()->getValue('SELECT SUM(quantity) AS sum FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.intval($cookie->id_cart).' AND `id_product` = '.intval($id_product)));


if ($quantity > 0 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $real_quantity)))


Why don't you replace the quantity value ( $quantity ) with $real_quantity in the if ?

I have also notice this bloc, but you don't wrote it :

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


- 1 : so, it could be wrote as :

$totalQuantity = $real_quantity + intval($quantity);


- 2 : $totalQuantity isn't use in this method.

PaymentMethod.php

$qty_result = Db::getInstance()->ExecuteS('SELECT SUM(quantity) AS sum FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.intval($cookie->id_cart).' AND `id_product` = '.intval($id_product));
$real_quantity = $qty_result[0]['sum'];
if ($product['cart_quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $real_quantity)))


same thing than before for Product.php for the if condition variable and the Db::getInstance()->ExecuteS.

And then juste fiew line after we can read :

'.(int)QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), intval($product['cart_quantity'])).',


This line is for the 'discount_quantity_applied' row for table order_detail, so i think that to be correct you should write

'.(int)QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), $real_quantity).',



Regards,

Zepe

Share this post


Link to post
Share on other sites

Zepe:

different people write in different styles, this is mine :)
it's not written in stone, and you obviously can write it differently and get the same results.

I kept the new quantity as a separate variable since it only concerns the discount and should no be confused with anything else.

In 1.3 there is an Unused total quantity variable, I left it there (I assume the PS team started doing something with it, and never finished)

I'll take a look at the last function call you mentioned...

Share this post


Link to post
Share on other sites
Is there a way to get quantity discounts regardless of attributes?
Example: add any 3 items to the cart at the standard price; add 1 more item and receive a 10% discount instantly on all items in the cart; add 5 more various items [in addition to the 4 existing items] and receive an additional 15% discount on all 9 items; and so on ... The items need not be related by any category or attribute.
Is this doable?
Thanks
Old Ken


So you basically want to have discounts affect all the products?

you will have to pick a Master product (the discount will be taken from it), and it will apply to all products.

Can be done, but requires more modifications..

Share this post


Link to post
Share on other sites
different people write in different styles, this is mine smile


No problems, I just want to share my opinion ( what I think ) :)

For the "totalQuantity", it's just that I think when someone makes a change to a script, he should take a look around and see if he could optimize, but this is only what i'm thinking.

Finally, tanks for sharing this source code, I'll take it ;)

P.S: excuse my bad english !


Zepe

Share this post


Link to post
Share on other sites

Is there a way to apply this to have category quantity discounts? For example, buy 3 items from category A and get a 10%...

Please let me know if this is possible. Thanks for sharing!

Share this post


Link to post
Share on other sites

Everything is possible ;)

However, that would require more customization, you can contact me via email about doing it as a paid job.

Share this post


Link to post
Share on other sites

V2 released - CRITICAL UPDATE!

The cart id which is used to calculate the quantity discount was used from $cookie and when a payment module confirms an order $cookie is empty, resulting in a payment error (since PS is expecting the full price).

The code was changed so it doesn't use $cookie in the order validation.

Share this post


Link to post
Share on other sites

I've installed the module directly into Prestashop. We have one product that has variable for size and colour.

If I buy 5 exactly the same, the discount works perfectly, if I buy 3 Large and 2 XLarge, the discount does not apply.

Have I not installed the module correctly or have I missed something altogether?

Iain

Share this post


Link to post
Share on other sites

I'm having a similar problem, I've installed the zip into modules and it says module installed successfully but it doesn't appear in the list. Could anyone provide some basic instructions on how to get this working?

Share this post


Link to post
Share on other sites
I'm having a similar problem, I've installed the zip into modules and it says module installed successfully but it doesn't appear in the list. Could anyone provide some basic instructions on how to get this working?


This is not a Module, it a modification.

You need to extract the zip file, and copy over the files inside into your Prestashop folder

There are 2 files in the attached zip, and they need to go into /classes/ in prestashop (replacing the existing files).

Share this post


Link to post
Share on other sites

Nice MOD, is there by anychange an easy way to change this so i gives a discount on the total amount in stead?

Share this post


Link to post
Share on other sites

This is just what I need! However, after replacing the two files, my product.php page comes up blank. The framework is there (the header and various blocks) but the product information is gone. The information is all still there on the back end. I am using version 1.3.3 with the version 1.3 file in your .zip. Any idea what's gone awry?

Share this post


Link to post
Share on other sites

The modified files are compatible up to 1.3.2, so you will have to manually merge them with the original files from 1.3.3

I suggest using a program called "Beyond Compare" which lets you easily compare and merge files.

I may add modified file for 1.3.3 at some point in the future when I have more free time.

Share this post


Link to post
Share on other sites

Ah ha. I can do that. I use Beyond Compare every day :-) Thanks!

Edit...unfortunately, I can't tell what's your code, and what's the new code in 1.3.3 so I'm not sure what to merge. I might just delete 1.3.3 and install 1.3.2 before I get too far down the road.

Share this post


Link to post
Share on other sites

is it possible with these modified files add discount only for a particular attribute?
Example if client buy 10 products (5 with attribute A and 5 with attribute B) to apply discount only with 5 with that attribute A for example?
thanks

Share this post


Link to post
Share on other sites

No, adding a discount to only 1 attribute will require a lot more modification, since there is no way in the backoffice to indicate which attribute (or combination) should have a discount.

It's possible to create such a modification, but it's certainly more than just a few line changes

Share this post


Link to post
Share on other sites

Is there any way to change this to give a discount based on the total amount of (different) items purchased?
Thanks

Share this post


Link to post
Share on other sites

PS 1.4 has a ton of great new features - I love it, but they haven't added this functionality. How hard will it be to modify this code to be compatible with PS 1.4 release? It is a very useful feature!

Share this post


Link to post
Share on other sites

Not that hard if you know your way around :)

I'll try to get to it when I have time, if not one else here can contribute.

Share this post


Link to post
Share on other sites

Anyone able to update the code for quantity_discounts_with_attributes.V2.zip so it is compatible with Prestashop 1.4? It is a shame they didn't include it as a standard option in the update. Having said that, I love what they have done with the flexibility in pricing now. A big step forward in my opinion.

Share this post


Link to post
Share on other sites
Anyone able to update the code for quantity_discounts_with_attributes.V2.zip so it is compatible with Prestashop 1.4? It is a shame they didn't include it as a standard option in the update. Having said that, I love what they have done with the flexibility in pricing now. A big step forward in my opinion.


Hello, everyone.

This feature is added in PS 1.4, but now, eliminated the discount for each attribute, as it was before PS 1.3.1

Example Prestashop-v1.3.1:

Skateboards Red: 10% to buy 10
Skateboards Blue: 20% to buy 20

If you add 5 Skateboards Red and 5 Blue receives no discount.

Example Prestashop-v1.4.0.17:

Skateboards Red: 10% to buy 10
Skateboards Blue: 20% to buy 20

If you add 5 Skateboards Red and 5 Blue , SI receives 10% discount. <<—— This has been the change

It would be good to have both options in the next version, it is necessary for many. :(

Share this post


Link to post
Share on other sites

 

 

Hello, everyone.

 

This feature is added in PS 1.4, but now, eliminated the discount for each attribute, as it was before PS 1.3.1

 

Example Prestashop-v1.3.1:

 

Skateboards Red: 10% to buy 10

Skateboards Blue: 20% to buy 20

 

If you add 5 Skateboards Red and 5 Blue receives no discount.

 

Example Prestashop-v1.4.0.17:

 

Skateboards Red: 10% to buy 10

Skateboards Blue: 20% to buy 20

 

If you add 5 Skateboards Red and 5 Blue , SI receives 10% discount. <<—— This has been the change

 

It would be good to have both options in the next version, it is necessary for many. :(

 

I have the same problem. I work with PS 1.4 and I want the discount calculation like it was for PS 1.3. I want separate discounts for each attribute.

For example:

I have used several discount prices for one product with different attributes:

- 20-40 = 0,55 euro/piece

- 50-90 = 0,45 euro/piece

- 100-190 = 0,35 euro/piece

- more than 200 = 0,30/piece

 

So far, no problem.

BUT my product has a combination of 24 colors. So 24 different "products".

 

The discount has to be like this:

20 pieces of color red = 0,55/piece

20 pieces of color green = 0,55/piece

50 pieces of color blue = 0,45/piece

 

==>3 different prices for one product with different attributes.

BUT the shopping cart calculates all these quantities together and makes: 90 pieces of 0,45/piece :-(

 

 

Can anyone help?

THANX

Share this post


Link to post
Share on other sites

Wow! Really fantastic, thanks for sharing it!

In PS 1.3.2.3 doesn't work, but I did the changes suggested by Zepe (thanks too) and it works.

 

However, Zepe's modifications were made before the tomerg3 V2 released - CRITICAL UPDATE! (I quote: "The cart id which is used to calculate the quantity discount was used from $cookie and when a payment module confirms an order $cookie is empty, resulting in a payment error (since PS is expecting the full price). The code was changed so it doesn't use $cookie in the order validation"). The result is that I have experimented some payment errors.

 

I have no idea of php, but I dared to modify the product.php code mixing both files (tomerg3 & zepe's ones) in this way:

 

// Get quantity including attributes //

$real_quantity = intval(Db::getInstance()->getValue('SELECT SUM(quantity) AS sum FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.intval($cart->id > 0?$cart->id:$cookie->id_cart).' AND `id_product` = '.intval($id_product)));

 

I tested it in my shop and the discount is applied in products with different attributes, but I didn't finished the order (because I don't want to make a payment to myself) so I will tell you the result after any customer buy anything.

Edited by c.carlos.s (see edit history)

Share this post


Link to post
Share on other sites

it's possible to update it for 1.5.4.1 ?

i have this problem , in shopping card , the discount dont work because of the different attributs...

thank's

Edited by Dagostino (see edit history)

Share this post


Link to post
Share on other sites

it's possible to update it for 1.5.4.1 ?

i have this problem , in shopping card , the discount dont work because of the different attributs...

thank's

 

 

Hi

 

¿Any solution for version 1.5?

 

Best regards

Share this post


Link to post
Share on other sites

Looking for a 1.5.x solution for this.

 

Anyone got it working yet?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

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