tomerg3 619 Posted October 27, 2010 Posted October 27, 2010 The following modification will allow you to use the quantity discount for all the products in the same default category, regardless of attributes.The discount will apply to all the products that have the same quantity discount and are in the same default category.I.E.Product A, Product B and Product C are all in the same category.Product A and B have q quantity discount of 10% for 5 items.The discount will apply for 1 X Product A (blue) + 1 X Product A (red) + 3X Product BIt requires making changes in 2 Prestashop classes.Prestashop 1.2.*/classes/PaymentModule.phpReplace // Quantity discount $reduc = 0.0; if ($product['quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['quantity']))) With // Get quantity including attributes for all products in the same default category // $result = Db::getInstance()->ExecuteS('SELECT a.id_product FROM '._DB_PREFIX_.'discount_quantity a, '._DB_PREFIX_.'discount_quantity b, '._DB_PREFIX_.'product p1, '._DB_PREFIX_.'product p2 WHERE b.id_product = '.$product['id_product'].' AND a.quantity = b.quantity AND a.value = b.value AND a.id_product = p1.id_product AND b.id_product = p2.id_product AND p1.id_category_default = p2.id_category_default'); foreach ($result AS $row) $in_product_discount .= isset($in_product_discount)?','.$row['id_product']:$row['id_product']; // Get total quantity including attributes // $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; // Quantity discount $reduc = 0.0; if ($product['quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $real_quantity))) Prestashop 1.3.*/classes/PaymentModule.phpReplace // Quantity discount $reduc = 0.0; if ($product['cart_quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['cart_quantity']))) With // Get quantity including attributes for all products in the same default category // $result = Db::getInstance()->ExecuteS('SELECT a.id_product FROM '._DB_PREFIX_.'discount_quantity a, '._DB_PREFIX_.'discount_quantity b, '._DB_PREFIX_.'product p1, '._DB_PREFIX_.'product p2 WHERE b.id_product = '.$product['id_product'].' AND a.quantity = b.quantity AND a.value = b.value AND a.id_product = p1.id_product AND b.id_product = p2.id_product AND p1.id_category_default = p2.id_category_default'); foreach ($result AS $row) $in_product_discount .= isset($in_product_discount)?','.$row['id_product']:$row['id_product']; // Get total quantity including attributes // $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; // Quantity discount $reduc = 0.0; if ($product['cart_quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $real_quantity))) Prestashop 1.2.* AND 1.3.*/classes/Product.phpReplace // Caching system $cacheId = $id_product.'-'.($usetax?'1':'0').'-'.$id_product_attribute.'-'.$decimals.'-'.$divisor.'-'.($only_reduc?'1':'0').'-'.($usereduc?'1':'0').'-'.$quantity; With $result = Db::getInstance()->ExecuteS('SELECT a.id_product FROM '._DB_PREFIX_.'discount_quantity a, '._DB_PREFIX_.'discount_quantity b, '._DB_PREFIX_.'product p1, '._DB_PREFIX_.'product p2 WHERE b.id_product = '.$id_product.' AND a.quantity = b.quantity AND a.value = b.value AND a.id_product = p1.id_product AND b.id_product = p2.id_product AND p1.id_category_default = p2.id_category_default'); foreach ($result AS $row) $in_product_discount .= isset($in_product_discount)?','.$row['id_product']:$row['id_product']; // Get quantity including attributes // $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; // Caching system $cacheId = $id_product.'-'.($usetax?'1':'0').'-'.$id_product_attribute.'-'.$decimals.'-'.$divisor.'-'.($only_reduc?'1':'0').'-'.($usereduc?'1':'0').'-'.$real_quantity.'-'.($id_customer ? $id_customer : '0');; And if ($quantity > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $quantity))) With if ($quantity > 0 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($id_product, $real_quantity))) Share this post Link to post Share on other sites
raffs 0 Posted November 1, 2010 Posted November 1, 2010 Hi Tomerg3,Can you give this a quick once over in case you missed something off it as I have tried this on a PrestaShop v.1.3.2 install and I could not get it to work for me.Thanks Share this post Link to post Share on other sites
tomerg3 619 Posted November 2, 2010 Posted November 2, 2010 Just did it for http://www.[My Website].com/1323upsdemo/category.php?id_category=2 (5 items 20% discount).I added to the cart 2 green shuffles, 2 pink Shuffles, 1 Nano, and I got the discount. Share this post Link to post Share on other sites
raffs 0 Posted November 2, 2010 Posted November 2, 2010 Hi TomergTried your site and it does work so I must be pasting in the code wrong. Damn!Would it be possible to let me see your modified Product.php and PaymentModule.php?Sorry if this sounds a bit forward but I've spent the last hour trying again to get this working on a V1.3.2.Raffs Share this post Link to post Share on other sites
tomerg3 619 Posted November 3, 2010 Posted November 3, 2010 Here are the files for PS 1.3.2. PaymentModule.php Product.php Share this post Link to post Share on other sites
raffs 0 Posted November 3, 2010 Posted November 3, 2010 TomergI would like to say a big Thank you, I have downloaded the two files and it works a treat. you're a genius!RaffsPS. on another note my friend in England purchased your Attribute Wizard Pro last week and hasn't stopped talking about it! Share this post Link to post Share on other sites
tomerg3 619 Posted November 5, 2010 Posted November 5, 2010 Glad to hear that, on both counts Share this post Link to post Share on other sites
jenjenj3n 0 Posted November 15, 2010 Posted November 15, 2010 This is awesome!Is there a way to mod it so that it only affects one category(or sub-category in my case)? I want to use this code for a "special" like "3 for 20" in a specific subcategory.Thanks in advance! Share this post Link to post Share on other sites
tomerg3 619 Posted November 15, 2010 Posted November 15, 2010 Change p1.id_category_default = p2.id_category_default'); To p1.id_category_default = p2.id_category_default AND p1.id_category_default = X'); X should be the ID of the category you want this to apply to.I haven't tested this, so try it out before using it on a live site. Share this post Link to post Share on other sites
Endrik 0 Posted November 17, 2010 Posted November 17, 2010 Is it possible to show in cart this discount and on the invoice? Like when I add 2 products then cart shows -5% and so on Share this post Link to post Share on other sites
tomerg3 619 Posted November 17, 2010 Posted November 17, 2010 This is a missing feature from Prestashop in general.I may address it at some point with a modification. Share this post Link to post Share on other sites
swankiat 0 Posted December 1, 2010 Posted December 1, 2010 I am not sure whether you guys encounter the problem I met after applying this code.The scenario is like this:When you added in certain quantities to get the discount, the price will be automatically changed to after-discount price at category page, but the product page will still show original price. It will confuse customers. Share this post Link to post Share on other sites
tomerg3 619 Posted December 1, 2010 Posted December 1, 2010 This is the way PS handles this, my Mod doesn't change that. Share this post Link to post Share on other sites
Jrw999 0 Posted December 16, 2010 Posted December 16, 2010 I tried using your files, coping and pasting even re-typing, but I never could get the product page to work with your code. Share this post Link to post Share on other sites
Jrw999 0 Posted December 16, 2010 Posted December 16, 2010 I am willing to pay someone for some work on my carts Share this post Link to post Share on other sites
tomerg3 619 Posted December 16, 2010 Posted December 16, 2010 what version of Prestashop are you using? Share this post Link to post Share on other sites
Jrw999 0 Posted December 16, 2010 Posted December 16, 2010 1.3.2 I believe or 1.3.3 I just downloaded it last week Share this post Link to post Share on other sites
tomerg3 619 Posted December 17, 2010 Posted December 17, 2010 This Mod was tested on PS 1.3.2.3, I did not test it on PS 1.3.3You can try to copy just the line numbers and not use the included files. Share this post Link to post Share on other sites
tacchan23 0 Posted January 22, 2011 Posted January 22, 2011 Hi, I'm using PS 1.3.6 and I just tried to "install" this mod.I tried with the provided files and also by manually replacing the code posted before. Sadly I always get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 SELECT SUM(quantity) AS sum FROM `ps_cart_product` WHERE `id_cart` = 10 AND `id_product` IN () Is there any way to fix it? or did I do something wrong? I would really LOVE to be able to use this very nice and useful discount feature Share this post Link to post Share on other sites
tomerg3 619 Posted January 28, 2011 Posted January 28, 2011 Try changing $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; To if ($in_product_discount != "") { $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; } else $real_quantity = $quantity; Share this post Link to post Share on other sites
8055 0 Posted February 11, 2011 Posted February 11, 2011 Change p1.id_category_default = p2.id_category_default'); To p1.id_category_default = p2.id_category_default AND p1.id_category_default = X'); X should be the ID of the category you want this to apply to.I haven't tested this, so try it out before using it on a live site. Just wondering can discount be applied to you specific categories only:For example i have to apply discount for category 5 and 9:I have tried p1.id_category_default = p2.id_category_default AND p1.id_category_default = 5 AND p1.id_category_default = 9 ');& p1.id_category_default = p2.id_category_default AND p1.id_category_default = 5 OR p1.id_category_default = 9 ');but no joy. Could somebody help me this issues please.Thanks in Advance Share this post Link to post Share on other sites
Mutix 0 Posted February 21, 2011 Posted February 21, 2011 Hello,First of all, thank you very much for this feature. I have tested it on PS 1.3.7 and it works very well.This is nearly what I was looking for. What I would like to do, is to extend this feature, not to products in a same category, but to the products in every category.For example, 5 products of cat 1, 5 products of cat 2, and 5 products of cat 3 = total 15 products, i would like to apply a discount on every product.Is this possible and could you point me in the right direction ?Many thanks,Regards Share this post Link to post Share on other sites
tomerg3 619 Posted February 22, 2011 Posted February 22, 2011 Mutix, try removing the follow part of the SQL query AND p1.id_category_default = p2.id_category_default Share this post Link to post Share on other sites
Mutix 0 Posted February 22, 2011 Posted February 22, 2011 Thanks a lot tomerg3, this works perfectly ! Share this post Link to post Share on other sites
Yoriel79 0 Posted April 4, 2011 Posted April 4, 2011 HiI have tried to apply the quantity discounts to my store and I have a problem with it.In my BO (Prestashop 1.3.7) appears the following message.Notice: Undefined variable: in_product_discount in /Applications/MAMP/htdocs/efimeracaenis/classes/Product.php on line 1448I have checked the line 1448. $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); The problem seems to be the variable "$in_product_discount".How can I fix it? Who can help me, please?Thanks for all. Share this post Link to post Share on other sites
tomerg3 619 Posted April 4, 2011 Posted April 4, 2011 Add $in_product_discount = "";after// Get quantity including attributes for all products in the same default category // Share this post Link to post Share on other sites
Yoriel79 0 Posted April 4, 2011 Posted April 4, 2011 I have it done, but I have the same problem.I am attaching the code, thanks.PaymentModule.php// Get quantity including attributes for all products in the same default category // $in_product_discount = ""; $result = Db::getInstance()->ExecuteS('SELECT a.id_product FROM '._DB_PREFIX_.'discount_quantity a, '._DB_PREFIX_.'discount_quantity b, '._DB_PREFIX_.'product p1, '._DB_PREFIX_.'product p2 WHERE b.id_product = '.$product['id_product'].' AND a.quantity = b.quantity AND a.value = b.value AND a.id_product = p1.id_product AND b.id_product = p2.id_product AND p1.id_category_default = p2.id_category_default'); foreach ($result AS $row) $in_product_discount .= isset($in_product_discount)?','.$row['id_product']:$row['id_product']; // Get total quantity including attributes // $qty_result = Db::getInstance()->ExecuteS('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` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; // Quantity discount $reduc = 0.0; if ($product['cart_quantity'] > 1 AND ($qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $real_quantity))) $reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value, new Currency(intval($order->id_currency))); 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($cart->id > 0?$cart->id:$cookie->id_cart).' AND `id_product` IN ('.$in_product_discount.')'); $real_quantity = $qty_result[0]['sum']; Share this post Link to post Share on other sites
tomerg3 619 Posted April 4, 2011 Posted April 4, 2011 You should also add it at the top of the change to product.php, which seems to be missing some code. Share this post Link to post Share on other sites
Yoriel79 0 Posted April 5, 2011 Posted April 5, 2011 Hi.I have tried to use the file that you have uploading, product.php, and I have same problem. I have thought that the problem maybe my data base. Maybe some variable is missing?Thanks. Share this post Link to post Share on other sites
cariss02 0 Posted April 6, 2011 Posted April 6, 2011 thanks so much tomerg3, you really help me..beside that, i also apply a discount if a total amount of buying for product in ALL category reached $50 (before the cut off prices), so all the product price in ALL category would be reduced by $0,6..Do you have any solutions to help me again ? thanks before..sorry about my english.. Share this post Link to post Share on other sites
NeilD 5 Posted May 9, 2011 Posted May 9, 2011 This looks like what I'm after... maybe. When i tried it on my local MAMP server it just brought up the white screen of death. But i assume thats because i am using prestashop 1.4. can i make some modifications to bring your creation to life? Share this post Link to post Share on other sites
tomerg3 619 Posted May 10, 2011 Posted May 10, 2011 I am swamped, but I will try to update this for 1.4 in the next week or so... Share this post Link to post Share on other sites
NeilD 5 Posted May 10, 2011 Posted May 10, 2011 Thanks so much that would be a great help Share this post Link to post Share on other sites
airbag 4 Posted July 1, 2011 Posted July 1, 2011 Hello tomerg3,We have on our site the words "Our Price:" before the price.But when I turn on quantity discounts module they dissapear. How can I add this to the module so they show?Can you show me where please? Share this post Link to post Share on other sites
tomerg3 619 Posted July 1, 2011 Posted July 1, 2011 Look in the tpl file (quantitydiscount.tpl). Share this post Link to post Share on other sites
airbag 4 Posted July 1, 2011 Posted July 1, 2011 Yes thanks, ive been looking at that for the last 2 hours!;-) function fetchCurrentPrice() {ldelim} var val = $("#our_price_display").text().replace(currencySign,''); var qd_price = ""; for (var i = 0 ; i < val.length ; i++) if (/[0-9.,]/.test(val.charAt(i))) qd_price += val.charAt(i); var arr = qd_price.split(","); if (arr[arr.length - 1].length == 2) qd_price = qd_price.replace(/,/g,'.'); else qd_price = qd_price.replace(/,/g,''); return parseFloat(qd_price); {rdelim} Is it this area? Share this post Link to post Share on other sites
tomerg3 619 Posted July 1, 2011 Posted July 1, 2011 No,It should be on this line discountStr += "{$qd_quantity_discount.from_quantity|intval} "; Share this post Link to post Share on other sites
airbag 4 Posted July 1, 2011 Posted July 1, 2011 tomerg3, thanks very helpful. Thank you for the reply! Share this post Link to post Share on other sites
airbag 4 Posted July 1, 2011 Posted July 1, 2011 Sorry tomerg3, I ment the main price display, not the quantitydiscount price display. Our main price has lost its text.. I assume your module is hiding the price and putting it back in again, then showing the quantitydiscounts below it.Where would I put the actual text in for the main price? Share this post Link to post Share on other sites
tomerg3 619 Posted July 1, 2011 Posted July 1, 2011 The module should not be hiding the price, if it is, it may be related to something custom in your theme... Share this post Link to post Share on other sites
drjdk 0 Posted July 7, 2011 Posted July 7, 2011 Great job tomerg3! Works like a charm Any progress in an update for v.1.4? Share this post Link to post Share on other sites
tomerg3 619 Posted July 7, 2011 Posted July 7, 2011 No, I have been so swamped lately, I have not gotten around to it, it's still high on my list. Share this post Link to post Share on other sites
Mercader Virtual 8 Posted July 12, 2011 Posted July 12, 2011 I will be waiting desperately for the 1.4 upgrade. THANKS A LOT! Share this post Link to post Share on other sites
Mercader Virtual 8 Posted July 27, 2011 Posted July 27, 2011 I will be waiting desperately for the 1.4 upgrade. <br/><br/>THANKS A LOT! I'm willing to pay for this. Can you please quote me ? Share this post Link to post Share on other sites
Jorge Gaitán 0 Posted July 27, 2011 Posted July 27, 2011 Tomerg3 Hello. Thank you for the file modifications to create quantity discounts. What should I change the files so that the quantity discount only applies to a group of clients, for example, by default. Thank you Share this post Link to post Share on other sites
TBean 0 Posted August 17, 2011 Posted August 17, 2011 Ah!!! This is what I have been looking for! But alas... like the Better Together module... it isn't working with 1.4... I am more optimistic and still have hope on this one! It seems tomerg3 is still actively helping in this thread! Thank you tomerg3! I look forward to your update on this for 1.4! Share this post Link to post Share on other sites
jennyboo 0 Posted September 2, 2011 Posted September 2, 2011 I think this is exactly what I need too! Anxiously watching for it in 1.4! Thanks so much in advance! Share this post Link to post Share on other sites
ryan_co 0 Posted November 2, 2011 Posted November 2, 2011 Just wanted to see if there has there been any progress on this mod for 1.4? Share this post Link to post Share on other sites
tomerg3 619 Posted November 7, 2011 Posted November 7, 2011 Sorry for the long delay, but it's finally here... http://www.prestashop.com/forums/topic/140803-module-category-quantity-discount-apply-quantity-discounts-across-all-products-in-a-category/ 1 Share this post Link to post Share on other sites
fernandokerber 16 Posted August 16, 2012 Posted August 16, 2012 How can I add an discount to all products in the store? Share this post Link to post Share on other sites
Recommended Posts