tazan Posted December 15, 2013 Share Posted December 15, 2013 Hi, I consider it a bug, but perhaps it is just one of the webshop things. Using Prestashop 1.5.6.0 Namely, if there are 2 customer and 10 chocolate bars. Then both customers can put 10 chocolate bars in their carts. If the customer 1 buys those 10 chocolate bars then the customer 2 can't buy them, the system will inform the customer 2, that the the shop doesn't have the chocolate bars anymore. But there is an exception to that. When both customers are in the payment step 5 before they make their purchase, then the system allows both of them to complete the purchase. Namely, if customer 1 is in payment step 5 and customer 2 makes a purchase of 10 chocolate bars which leaves the stock to 0. But the customer 1 who has previously also put 10 chocolate bars in the cart can also finish the purchase, without the system stopping him. Which totals in -10 chocolate bars. I experienced this with my new shop. Except it wasn't a chocolate bar. It seems a very rare case to happen. Because the both customers have to have the same products. The total of the chocolate bars in the cart, for both customers, has to be higher than available stock. One customer has to be in the payment 5 step while the other one makes the purchase. It is very likely that I will never experience it again, as I will have more products and bigger stock later on. Nevertheless it caused a problem. I would like to know if this is a bug or is it a webshop anomaly that one has no way around? Sincerely, Hendrik Link to comment Share on other sites More sharing options...
bellini13 Posted December 16, 2013 Share Posted December 16, 2013 It is most likely just an oversight by the developers and how PS was designed. The validation for stock occurs at the point the product is added to cart. So in your scenario 10 existed and both customers are allowed to add. I have not tested this so I'm just going by what you have stated, but it sounds like the PaymentModule validateOrder function should have code to check that stock is still available. There are likely several factors to consider 1) Is stock management enabled. Is advanced stock management enabled 2) In your scenario, was customer 2 order split into 2 orders? The first for items that are available, and the second for items that are not available? 3) What are your out of stock settings configured to? Allow or Not Allow? 4) You should also consider at which step to add any additional validation. Since we know the quantity is checked during the add to cart, technically I can add products to the cart today, leave the store and come back a week later and complete the order. What happens if stock is no longer available a week later? Does Prestashop stop the order at any point during checkout? How far have you really tested this? I do see this code after the order is created, but I have not stepped into that code to determine what it is doing. // updates stock in shops if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $product_list = $order->getProducts(); foreach ($product_list as $product) { // if the available quantities depends on the physical stock if (StockAvailable::dependsOnStock($product['product_id'])) { // synchronizes StockAvailable::synchronize($product['product_id'], $order->id_shop); } } } Link to comment Share on other sites More sharing options...
lfcuesta Posted December 17, 2013 Share Posted December 17, 2013 I have the same problem that you, It´s a big problem, ¿Are there any solution? Link to comment Share on other sites More sharing options...
tazan Posted December 17, 2013 Author Share Posted December 17, 2013 There are likely several factors to consider 1) Is stock management enabled. Is advanced stock management enabled 2) In your scenario, was customer 2 order split into 2 orders? The first for items that are available, and the second for items that are not available? 3) What are your out of stock settings configured to? Allow or Not Allow? 4) You should also consider at which step to add any additional validation. Since we know the quantity is checked during the add to cart, technically I can add products to the cart today, leave the store and come back a week later and complete the order. What happens if stock is no longer available a week later? Does Prestashop stop the order at any point during checkout? How far have you really tested this? 1. I don't have either installed. 2. I made 2 different customers and used different browsers for both customers. Neither of the orders were split. What exactly do you mean by the rest of the question? 3. Settings are, not to allow out of stock orders. 4. You are correct, quantity is always checked and it works. except in one case. It works when: To start the scenario we need 10 chocolate bars in the shop. Customer 1 comes and adds 10 chocolate bars to the cart. Customer 2 comes and adds 10 chocolate bars to the cart. Customer 1 starts the check out and stops at step 4. Customer 2 starts the check out and finishes the order. 0 chocolate bars in stock. Customer 1 wants to go to step 5, but will get a message that the shop is out of chocolate bars because customer 2 bought all the chocolate bars. 0 chocolate bars in stock. All works fine. It doesn't works when: To start the scenario we need 10 chocolate bars in the shop. Customer 1 comes and adds 10 chocolate bars to the cart. Customer 2 comes and adds 10 chocolate bars to the cart. Customer 1 starts the check out and stops at step 5. Customer 2 starts the check out and finishes the order. 0 chocolate bars in stock. Customer 1 continues with the payment. But the shop doesn't stop or inform the customer 1 that the there are no more chocolate bars and allows to finish the purchase -10 chocolate bars in stock. Fails. Week later: Haven't tested it like that, but the system doesn't allow to start a checkout when the product is out of stock. I have tested it to an extent to see where the system starts failing and when it does work the way it is suppose to. So i looked for the borderline. I was able to produce the -2 stock my self (I used the above explained scenario to produce -2 stock). I also examined the real life scenario in my shop that produced stock -2, and it showed that 2 orders that bought the last items were submitted within 1 minute and 30 seconds. You may go to my shop at www.tastegood.dk then you will see how our check out process works. There is no guest check out available. I will look into the code my self in the weekend. Thanks for the reply Link to comment Share on other sites More sharing options...
tazan Posted December 17, 2013 Author Share Posted December 17, 2013 (edited) I have the same problem that you, It´s a big problem, ¿Are there any solution? I will post the solution here, if I get it solved, otherwise it is the job of Prestashop staff. Don't wait for the solution before next week. Don't have time to deal with it before. Edited December 17, 2013 by tazan (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted December 18, 2013 Share Posted December 18, 2013 1) Is stock management enabled. Is advanced stock management enabled 1. I don't have either installed. You are trying to test how Prestashop reacts when a product is out of stock, yet you do not have stock management enabled? What am I missing? Link to comment Share on other sites More sharing options...
tazan Posted December 18, 2013 Author Share Posted December 18, 2013 You are trying to test how Prestashop reacts when a product is out of stock, yet you do not have stock management enabled? What am I missing? Correct, tho those modules are not free, therefore I do not have them. Prestashop handles out of stock situations as expected, except my explained scenario. Link to comment Share on other sites More sharing options...
stottycabanas Posted December 19, 2013 Share Posted December 19, 2013 Those stock management functions aren't 'modules', they are standard Prestashop features. In your back office, got to Preferences->Products, scroll down to the bottom section Products stock. These are the settings bellini13 was asking about. Take a screenshot & post it here. Cheers, Dave Link to comment Share on other sites More sharing options...
tazan Posted December 19, 2013 Author Share Posted December 19, 2013 (edited) Those stock management functions aren't 'modules', they are standard Prestashop features. In your back office, got to Preferences->Products, scroll down to the bottom section Products stock. These are the settings bellini13 was asking about. Take a screenshot & post it here. Cheers, Dave Apparently I do have stock management enabled. I will try out also that advanced stock management Edited December 19, 2013 by tazan (see edit history) Link to comment Share on other sites More sharing options...
tazan Posted December 24, 2013 Author Share Posted December 24, 2013 So I have debugged the issue a little and found out what is causing the problem. On step 5 where you select the payment method, Prestashop passes the order processing over to a module. But those modules do not validate the cart state as Prestashop does. They just make sure that you make the payment. ( I know it because Prestashop uses OrderController in payment steps 1-5, which calls checkQuantity() method of the class Cart, to validate the order). But the modules do not call the checkQuantity() method in class Cart. So the solutions are, either to modify every single payment module you have to call Cart->checkQuantity() method. Or let Prestashop to force payment module cart validation somehow. Either way the solution isn't easy. In the end I think the best solution is for Prestashop team to change the core, to force every payment module to go through the final check (after the payment information is accepted), on the cart and inventory state and only then automatically finalize the order and submit the payment. Otherwise 2 payment modules can work parallel and do what every they want Link to comment Share on other sites More sharing options...
IrishGuy Posted May 9, 2016 Share Posted May 9, 2016 Has anyone found a solution to this yet? I will be selling high priced items with potential to have high demand for small quantities. If two customers come in at the same time and order over the stock quantity between them they are still allowed to pay based off my testing. Example: Stock QTY of 3 Customer 1 orders 2 Customer 2 orders 2 at same time Both customers can pay but only have 3 products instead of 4. I have enabled stock management and my payment gateway is PayPal Europe. Is there a way around it? 1 Link to comment Share on other sites More sharing options...
Recommended Posts