Med6 Posted April 23, 2014 Share Posted April 23, 2014 Hello I want to set the maximum quantity order of a product if I have a product P.. only 4 items of this Product is allowed per customer Link to comment Share on other sites More sharing options...
vekia Posted April 23, 2014 Share Posted April 23, 2014 i suggest to use module like mine maximum product quantity it allows to define what is the maximum quantity of product in cart, or what is the quantity limit for all orders Link to comment Share on other sites More sharing options...
PascalVG Posted April 24, 2014 Share Posted April 24, 2014 Hi Vekia, No he wants not a fixed limit of x products per order, he wants a maximum amount per product, but with possibly more different products per order. I suggested to open a new topic... pascal Link to comment Share on other sites More sharing options...
PascalVG Posted April 24, 2014 Share Posted April 24, 2014 OK, try this: override classes/Cart.php (see prestashop developers documentation on how) or change directly in classes/Cart.php: (Make backup, just in case!) modify the function: (sample code from PS version 1.5.5.0) public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true) ... /* If we have a product combination, the minimal quantity is set with the one of this combination */ if (!empty($id_product_attribute)) $minimal_quantity = (int)Attribute::getAttributeMinimalQty($id_product_attribute); else $minimal_quantity = (int)$product->minimal_quantity; if (!Validate::isLoadedObject($product)) die(Tools::displayError()); if (isset(self::$_nbProducts[$this->id])) unset(self::$_nbProducts[$this->id]); if (isset(self::$_totalWeight[$this->id])) unset(self::$_totalWeight[$this->id]); if ((int)$quantity <= 0) return $this->deleteProduct($id_product, $id_product_attribute, (int)$id_customization); elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE')) return false; elseif ($quantity > 4) { // For example, 4 max per same product/product-combination allowed return false; } else { /* Check if the product is already in the cart */ $result = $this->containsProduct($id_product, $id_product_attribute, (int)$id_customization, (int)$id_address_delivery); /* Update quantity if product already exist */ if ($result) { if ($operator == 'up') { $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity FROM '._DB_PREFIX_.'product p '.Product::sqlStock('p', $id_product_attribute, true, $shop).' WHERE p.id_product = '.$id_product; $result2 = Db::getInstance()->getRow($sql); $product_qty = (int)$result2['quantity']; // Quantity for product pack if (Pack::isPack($id_product)) $product_qty = Pack::getQuantity($id_product, $id_product_attribute); $new_qty = (int)$result['quantity'] + (int)$quantity; if ($new_qty > 4) { // For example, 4 max per same product/product-combination allowed return false; } $qty = '+ '.(int)$quantity; ... And save the file. Reload the product page and try to add the same product, or the same product combination 5 times. The 5th time it should complain. Try another product or product-combination and this time it should be able again to add to the cart, up to 4 times. the 5th time it should complain again. So we can have of each product or product-combination a max of 4 per order. So you see, you can have unlimited different products per order, but of each product not more than 4 in that order. If you (also) want to limit the maximum amount of products per order (of any product or product-combination), you can have a look in the link Vekia mentioned above. There I limited the total amount of products per order. Hope this helps, pascal. 4 Link to comment Share on other sites More sharing options...
vekia Posted April 24, 2014 Share Posted April 24, 2014 Hi Vekia, No he wants not a fixed limit of x products per order, he wants a maximum amount per product, but with possibly more different products per order. I suggested to open a new topic... pascal sorry for my misunderstading i saw a lot of posts related to second topic where you discussed a lot with brilliant code solutions, i thought that problem was solved and this is only a duplication my bad, now i know that i have to read topic twice before posting Link to comment Share on other sites More sharing options...
Med6 Posted May 2, 2014 Author Share Posted May 2, 2014 Thank you pascal. have a nice day Link to comment Share on other sites More sharing options...
PascalVG Posted May 3, 2014 Share Posted May 3, 2014 Hi Med6, Glad it works :-) I'll mark the topic as solved. Happy selling, pascal Link to comment Share on other sites More sharing options...
RomsWebDesign Posted May 14, 2014 Share Posted May 14, 2014 Is there a way to do that from a module, example from actionCartSave ? I would like to limit overrides. Thanks. Link to comment Share on other sites More sharing options...
PascalVG Posted May 15, 2014 Share Posted May 15, 2014 Rom, well, you could build a module around it that copies the override for you to the correct position, but you still have to change this function, so really without any overrides is not possible as far as I can see now... There are no hook you could use to change/check the quantity afterwards or cancel the addition afterwards, I believe. pascal. Link to comment Share on other sites More sharing options...
RomsWebDesign Posted May 15, 2014 Share Posted May 15, 2014 ok thank you. In fact, my client does not really want to limit the order quantity for these products. He just want to change the operating mode of the cart. Instead of incrementing the quantity of products it want it added a line in the cart. I do not know if I'm clear. In the screen below. We see that the same product was added 3 times. I create a new topic => http://www.prestashop.com/forums/topic/330679-not-update-product-quantity-in-cart-but-create-new-cart-item/ Thanks Link to comment Share on other sites More sharing options...
dursunj Posted August 8, 2014 Share Posted August 8, 2014 hi, I have an issue with prestashop, something similar to this thread. My client the customer just to be able to purchase 1 particular product at a time but the latter can increase its quantity. For example, let sat i have 3 products. Product A Product B Product C At any given type a user can i any product in his cart.(for example Product A), now if i wish to add Product B, i get an error, but if i want to increase the quantity for Product A, i can do that. How can i do that with your above code. Link to comment Share on other sites More sharing options...
PascalVG Posted August 8, 2014 Share Posted August 8, 2014 Hi Dursunj, quote: now if i wish to add Product B, i get an error, but if i want to increase the quantity for Product A, i can do that Do you mean that YOU, as seller should be able to increase afterwards, or the CUSTOMER him/herself can choose more quantity of just one product? pascal Link to comment Share on other sites More sharing options...
dursunj Posted August 8, 2014 Share Posted August 8, 2014 customer Link to comment Share on other sites More sharing options...
Futureproject Posted March 19, 2015 Share Posted March 19, 2015 Guys, Could you update it so it'll work in 1.6? Link to comment Share on other sites More sharing options...
Futureproject Posted March 19, 2015 Share Posted March 19, 2015 I need to allow to buy only one product/user, including order history. The best solution would be to inform when adding to cart that he already has bought this product. Link to comment Share on other sites More sharing options...
Pietro Mantovani Posted March 27, 2015 Share Posted March 27, 2015 HI, I would like to try this mod in Prestashop 1.6.9, any suggestion? Link to comment Share on other sites More sharing options...
PascalVG Posted March 28, 2015 Share Posted March 28, 2015 Pietro, For 1.6, just add red code like in my post #4. 1.6 code is almost the same as 1.5 (They added some hook), but if you look at lines just before/after the red lined I added, you should be able to find the correct place in your Cart.php file pascal Link to comment Share on other sites More sharing options...
Pietro Mantovani Posted March 30, 2015 Share Posted March 30, 2015 Thank you very much Pascal, it works! Link to comment Share on other sites More sharing options...
PascalVG Posted March 30, 2015 Share Posted March 30, 2015 Hi Pietro, thanks for the confirmation. Good to hear! Happy selling, pascal 1 Link to comment Share on other sites More sharing options...
PetrolCulture Posted April 14, 2016 Share Posted April 14, 2016 Hi! It worked well on PrestaShop 1.6 But I have another problem: I want to limit the overall amount of a product, despite the attributes. As example, I limited the quantity for 1. My product has 2 different attributes (color). The consumer can buy 1 product of a color and then another 1 product of the other color. But I need to limit this. The consumer could only buy 1 product at all. (but other products per order) Is there a way I can do that? Thanks! Link to comment Share on other sites More sharing options...
Tirips Posted November 2, 2017 Share Posted November 2, 2017 Works nice on 1.6.1.7..... but DON'T FORGET to add an "}" at the start of the first red line (2 hours wasted due to my lack of concentration ) Link to comment Share on other sites More sharing options...
Murphy Posted February 9, 2018 Share Posted February 9, 2018 (edited) For people who needs to limit the max quantity on only a certain product (which i do), you can try adding the following code. On 4/24/2014 at 1:16 PM, PascalVG said: if ((int)$quantity <= 0) return $this->deleteProduct($id_product, $id_product_attribute, (int)$id_customization); elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE')) return false; elseif ($quantity > 4 && $id_product =='XXX') { // Where XXX is the product id. For example, 4 max per same product/product-combination allowed return false; } else { /* Check if the product is already in the cart */ $result = $this->containsProduct($id_product, $id_product_attribute, (int)$id_customization, (int)$id_address_delivery); /* Update quantity if product already exist */ if ($result) { if ($operator == 'up') { $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity FROM '._DB_PREFIX_.'product p '.Product::sqlStock('p', $id_product_attribute, true, $shop).' WHERE p.id_product = '.$id_product; $result2 = Db::getInstance()->getRow($sql); $product_qty = (int)$result2['quantity']; // Quantity for product pack if (Pack::isPack($id_product)) $product_qty = Pack::getQuantity($id_product, $id_product_attribute); $new_qty = (int)$result['quantity'] + (int)$quantity; if ($new_qty > 4 && $id_product =='XXX') { // Where XXX is the product id. For example, 4 max per same product/product-combination allowed return false; } Edited February 9, 2018 by Murphy (see edit history) Link to comment Share on other sites More sharing options...
Super Gift Posted July 19, 2018 Share Posted July 19, 2018 Hi, I'm currently using prestashop 1.7. I would like to limit my customer to order maximum 4 liters in total for any products in one order. (*chemical product which there's limitation of order maximum 4 liters). Any order more than 4 liters is not allowed. May I know how to set a limitation for this case? Link to comment Share on other sites More sharing options...
Rajan Posted November 28, 2019 Share Posted November 28, 2019 Any one kindly update... How to limit one customer maximum 5 qty of sky products at a time per day.... Link to comment Share on other sites More sharing options...
jayb174 Posted April 9, 2020 Share Posted April 9, 2020 Anyone knows how to successfully implement this solution in Prestashop 1.7.6.4? Link to comment Share on other sites More sharing options...
gejrot Posted May 31, 2020 Share Posted May 31, 2020 On 2/9/2018 at 8:02 AM, Murphy said: For people who needs to limit the max quantity on only a certain product (which i do), you can try adding the following code. Just learn prestashop during covid19, and found this helpful article. if i need to limit max quantity base on category or manufacturer, how can we do it ? i try the code as you provide and change the $id_product with $id_manufacturer. and it's not working. any suggestion ? thanks in advanced Link to comment Share on other sites More sharing options...
zon3d Posted September 1, 2021 Share Posted September 1, 2021 I posted in this other thread with the code on how to limit the total quantity of particular products that can be added to the cart (eg: can be used to limit the total quantity allowed for all those products in a certain category or by a certain manufacturer, etc) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now