Prestashop: No additional quantity check on order confirmation, negative quantites

Created on 29 Sep 2018  ·  23Comments  ·  Source: PrestaShop/PrestaShop

Describe the bug
Follow steps below.

Details of the scenario :

  • Different customers add the last quantity of a product to their cart at the same time
  • they all reach the last step of the funnel (payment step). During the previous steps, PrestaShop has controlled the remaining stock, and as long as there is at least 1 product remaining, customers are allowed to reach the final step.
  • In theory, the first customer who pays and validates his order should get the one last unit and other customers should be prevented from buying it. But in reality, all these customers are allowed to pay (either check, bankwire, paypal, payplug, hipay, etc...), so this causes a big issue.
    ==> Because all orders are considered valid, even though the product stock does not allow it (option "deny out of stock orders), and this results in negative stock. This is even more complicated to handle when it is related to a direct payment (credit card / paypal / stripe).

To Reproduce
Steps to reproduce the behavior:

  1. Set selected product quantity to for example 2
  2. Add this product to cart, 2 units
  3. Go to the last step of the checkout, just before you click "Confirm with an obligation to pay"
  4. Now, change quantity of the product to 1 in back-office
  5. Click "Confirm with an obligation to pay" on last step of the checkout.

Aaaaand... we have an order with 2 units of the product which was available with only 1 unit in stock.

We need additional checks just before submitting order to avoid negative quantities and many logistic problems.

Additionnal information
PrestaShop version: 1.7.0.0 to 1.7.5.0
PHP version: N/A

1.6.1.24 1.7.4.2 Bug Checkout FO Major TBS Topwatchers waiting for dev

Most helpful comment

Here is a solution that Axome gave us :

  • when customers reach the payment step, re-check stocks again (already done on the classic theme)
  • when customers proceed to the payment, bank modules should be in "authorization" mode only : this allows to validate if the purchase is possible or not (the customer has virtually proceeded to the payment on the bank or payment platform).
  • When returning to PrestaShop (PaymentModule::validateOrder method), there should then be a check on the stock and proceed to the order capture and creation ONLY if the stock allows it.
  • If the stock does not allow it, the customer is redirected to his cart with an error message "this product is no longer available".

@eternoendless @PrestaShop/prestashop-core-developers @kpodemski @rGaillard what do you think of this solution ?

Apparently this bug was already present in 1.6. Can someone confirm ?

All 23 comments

Hi @kpodemski,

Thanks for your report.
I manage to reproduce the issue with the last version 1.7.4.2 / branch 1.7.5.x.
This PR: #8752 do not check the quantity of products available in the last step.
@marionf what do you think?

Best regards, Khouloud

Hello @kpodemski
Yes, we are aware of this and we talked about it with @alegout & @rGaillard when we added stock verification at each step but unfortunately for some technical reasons, we can't add this verification at the last step
@rGaillard if you want specify the technical reasons

@rGaillard explained me this :
In any case, there will always be a step where you will not be able to check the stock, for example on the payment provider's page
Adding an ajax check at the click of the button may slow down the process for the merchant's customer

@marionf

i agree, but... maybe it would be a good idea to give merchants a choice, at this moment it is considered as bug by many people and unfortunately causing a lot of issues

➤ marionf commented:

Hello @kpodemski
Yes, we are aware of this and we talked about it with @alegout & @rGaillard when we added stock verification at each step but unfortunately for some technical reasons, we can't add this verification at the last step
@rGaillard if you want specify the technical reasons

hey @rGaillard could you tell me more about those technical issues?

@PrestaShop/prestashop-contributors what do you guys think ?

At this step your customer can be on your payment gateway payment page, how do you handle this case? You just refuse the return of your payment gateway with no link between your shop and your payment gateway? This is a bad idea...

Hmmm, you won't be on payment gateway before clicking "Payment with an obligation to pay", right? We're talking about 1.7 only of course, the only issue i see could be with PayPal Express module and modules which skips this step...

Here is a solution that Axome gave us :

  • when customers reach the payment step, re-check stocks again (already done on the classic theme)
  • when customers proceed to the payment, bank modules should be in "authorization" mode only : this allows to validate if the purchase is possible or not (the customer has virtually proceeded to the payment on the bank or payment platform).
  • When returning to PrestaShop (PaymentModule::validateOrder method), there should then be a check on the stock and proceed to the order capture and creation ONLY if the stock allows it.
  • If the stock does not allow it, the customer is redirected to his cart with an error message "this product is no longer available".

@eternoendless @PrestaShop/prestashop-core-developers @kpodemski @rGaillard what do you think of this solution ?

Apparently this bug was already present in 1.6. Can someone confirm ?

yes 1,6,1,24 have this bug too any fix_

ping @PrestaShop/prestashop-core-developers

I'll be happy to discuss this solution with you!

Here is a solution that Axome gave us :

  • when customers reach the payment step, re-check stocks again (already done on the classic theme)
  • when customers proceed to the payment, bank modules should be in "authorization" mode only : this allows to validate if the purchase is possible or not (the customer has virtually proceeded to the payment on the bank or payment platform).
  • When returning to PrestaShop (PaymentModule::validateOrder method), there should then be a check on the stock and proceed to the order capture and creation ONLY if the stock allows it.
  • If the stock does not allow it, the customer is redirected to his cart with an error message "this product is no longer available".

Our issue in closer look. We use ASM

Customer make cart and put items in them in one day, but doesnt process cart, not order. Next day some items comes 0 and system not allow to put them in new cart. So the safety order 0 products is OK. After that the customer come back to own cart from day ago and order without any trouble. The 0 items are ordered and we see -1 pcs on those items.
As far as i remeber this bug we meet much earlier then in 1.6.1.24. We use custom template, can be this issue of the template or core system?

I'm suffering this issue last days... Last Friday, I've reached -10 in a product stock because of this issue. So 10 customers that are dissapointed... 10 we are so sorry emails... 10 refunds.

What would be the best approach to solve this? I'm not talking about a technical solution.
What would be, in theory, the best solution?

This answer from Tobi (Shopify) from 2007:

One example of something we do behind the scenes is that items are “reserved” when a customer moves to the payment step. For 5 minutes the products in his/her cart are reserved for the buyer. This accommodates people who have to go hunting their house for their credit card whenever they want to buy online :)

Here is a solution that Axome gave us :

  • when customers reach the payment step, re-check stocks again (already done on the classic theme)
  • when customers proceed to the payment, bank modules should be in "authorization" mode only : this allows to validate if the purchase is possible or not (the customer has virtually proceeded to the payment on the bank or payment platform).
  • When returning to PrestaShop (PaymentModule::validateOrder method), there should then be a check on the stock and proceed to the order capture and creation ONLY if the stock allows it.
  • If the stock does not allow it, the customer is redirected to his cart with an error message "this product is no longer available".

@eternoendless @PrestaShop/prestashop-core-developers @kpodemski @rGaillard what do you think of this solution ?

Apparently this bug was already present in 1.6. Can someone confirm ?

@colinegin when you say that Axome gave you that solution... Do you mean a working solution? Is already implemented in your site? If yes, I'm very interested, and I would like to talk with them.

This bug is a very serious headache for me... I'm having a lot of orders with negative stock.

Hi @anfuca

Unfortunately, this is not a working solution, but rather a proof of concept. We had to think of a solution for this problem for one of our customers, and we ended up with this idea.

It still needs to be reviewed by prestashop core team because it has a lot of implications:

  • The final stock check should be a feature you can toggle on or off in the admin panel, because all payment gateways can't comply with this out of the box
  • There should be additional documentation on this feature in the admin panel
  • We can imagine that compatible addons could have a specific tag / label to help merchants choose the right payment module

This being said, if you only use direct payment modules (card or paypal) that can be configured in "authorization only" mode, to have a working solution you would need to:

  • Override the PaymentModule::validateOrder method to check stocks before creating the order
  • Handle the different use-cases (OK ? Error ? Other ?) : let the order creation process, or go back to cart summary
  • Capture the payment (depends on payment gateway, either you can do this with their code, or with their API)

Would like to follow and support the idea of "holding" the 5 minutes reserved stock while processing the payment, and check the stock right before the payment step.

Another idea is to force payments addons to send a stock check and throw a payment error if the stock is not available anymore, would help with this concurrency issue a lot.

We developped a module with this in mind plus some "real time" capabilities that can be disable for avoiding high server workload :
https://addons.prestashop.com/en/stock-supplier-management/21707-temporary-product-reservation-lonely-stock.html

It creates a separate database and mostly rely on updateQty hook.
Module is sold since more than 3 years now, fully functionnal and debugged. Feel free to ask questions about this if needed, you can also take a look at our FAQ here : https://www.malttt.com/faq-products/?lang=en

@MattLoyeD your module is a nice workaround, and we used it for one of our projects :smile:

We had severe performance issues that we managed to fix in the module (database indexes, externalized CRON task, etc.), I would be happy to share these optimizations with you :wink:

@nsorosac So so true. That module has a very bad and serious perfomance problems. I would like to know those optimizations!

well the check of stock in the last step seems someone have found a way to do it: https://addons.prestashop.com/it/gestione-scorte-fornitori/48536-checking-stock-at-checkout-before-paying.html#specifications

why not implementing on Prestashop Core too?

We developped a module with this in mind plus some "real time" capabilities that can be disable for avoiding high server workload :
https://addons.prestashop.com/en/stock-supplier-management/21707-temporary-product-reservation-lonely-stock.html

It creates a separate database and mostly rely on updateQty hook.
Module is sold since more than 3 years now, fully functionnal and debugged. Feel free to ask questions about this if needed, you can also take a look at our FAQ here : https://www.malttt.com/faq-products/?lang=en

your module is nice but it remove all abandoned cart, and remarketing on abandone cart is a big money recovering.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

onlinedhlx picture onlinedhlx  ·  66Comments

attractive picture attractive  ·  80Comments

e-perrodon picture e-perrodon  ·  69Comments

krasnycz picture krasnycz  ·  52Comments

photinia73 picture photinia73  ·  59Comments