Adding to cart when out of stock

Here are some testing notes on the branch products-caching-add-to-cart. This feature deals with the situation where a product is in the cart or being added to the cart, and in that process it becomes out of stock. This branch deals with four scenarios:

  1. When there’s an out of stock product in the cart, and the user visits the shopfront, they are taken to the cart and an out of stock message is displayed.
  2. When there’s an out of stock product in the cart, and the user visits the checkout, they are returned to the cart and an out of stock message is displayed.
  3. When there’s an out of stock product in the cart, and the user attempts to place an order, they are returned to the cart and an out of stock message is displayed.
  4. When the user attempts to add an out of stock product to the cart, or when they try to add a greater quantity to their cart than is available, a message is displayed and the amount in their cart is reduced.

All of these should take effect for both quantity and max quantity (for group buy items).

In terms of testing, I’ve had good mileage by using two tabs, one for the shopfront and the other for the admin to modify stock levels.

See also:

Hey Rohan, I tested this in scenarios that don’t quite match yours. But you can see that going to the shopfront with invalid QTY = correct. Visiting final checkout page with invalid QTY = correct. But visiting edit cart page with invalid QTY = sometimes incorrect. Your item 4, Olivier’s wishlist item, is also the same as it usually is, with no error message, thus still broken.

  1. I’m at the edit cart page, my cart products are all in stock. But then the shop enterprise then reduce stock on hand.
  • If I click continue shopping: Page reloads, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  • If I click checkout: Page reloads, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  • If I click ‘update’: Page reloads, NO red banner appears, text next to item appears “insufficient stock available…”. INCORRECT- i should get the red error banner too.
  1. I’m in the shopfront. I have valid amounts in my cart. But then the shop enterprise then reduce stock on hand.
  • If I click Edit your Cart (at bottom of page, or cart at top right corner)- I go to edit cart page, NO red banner error shows, text next to item appears “insufficient stock available…” INCORRECT- i should get the red error banner too.
  • If I click checkout now, in cart at top right corner. I go to edit cart, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  • If I refresh the shopfront. I go to edit cart page, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  1. I’m at edit cart and my cart is valid. I click checkout. While at the checkout page the shop enterprise then reduce stock on hand.
  • If try to place my order. I go to edit cart, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  • If I click Back to Cart button- I go to edit cart page, NO red banner error shows, text next to item appears “insufficient stock available…” INCORRECT- i should get the red error banner too.
  • If try to go back to shop (by typing URL). I go to edit cart, red banner error shows, text next to item appears “insufficient stock available…” CORRECT
  1. I’m at the editing my cart page. I have the full on hand value in cart, I try to add 1 more, I click update. I don’t see red error banner, but get large alert…“1 error prohibited this record from being saved: There were problems with the following fields: Line items quantity exceeds available stock. Please ensure line items have a valid quantity.” and the text next to item appears “insufficient stock available…” . The QTY remains at invalid amount. I can then click ‘checkout’ or return to shop. In both cases I’m allowed to do so, but my QTY will go back to the valid amount. SUGGESTED IMPROVEMENT. When the text appears, the QTY should go back to the valid amount, currently I’m not certain my increased order has been rejected.

  2. I’m in the shopfront. I want to order 20 leeks, there is only 10 on hand. I type 20. My 20 turns into 10. There is no warning or reason given. INCORRECT- a message should be displayed.

The shopfront stockout message is being strange.

This happened again… I stocked out a product as the enterprise. In the shop a different product was shown to stock out. It seems like the stockout occurs to one of the next products I try to add to my cart, not the actual product which has the stockout.

Also the stockout message is very delayed, not instant. Sometimes it comes, applied to a different product. Other times it doesn’t come at all.

There is no x button to close the message that pops up. You just have to click on the background and it goes away, but some people might not know that.

The same behaviour is occurring for Group Buy products, simply looking at the Min value. Errors don’t show if the Max value exceeds what’s on hand after a stockout. I can proceed through checkout with a min value of 1 and max value of 3 when the on hand is changed to 2. Max values disappear when I return to the shopfront, plus the edit cart page doesn’t have the Max value field, so it’s hard to see how that value is being treated.

End testing.

Testing notes April 22nd

  • The red error banner message is appearing when stock levels in the cart are no longer valid because On Hand has reduced. FIXED. However it would be consistent for the QTY to be reduced to the On Hand value, as occurs in the shop. Similarly, invalid QTYs enetered by a customer still get treated the same (4 and 5 above), and Rohan plans to make this more consistent in the next batch of fixes.
  • The “Reduced Stock Available” message in the shopfront is appearing for the correct items. And there is a x close button. FIXED
  • Max values are held in the shopfront if you return to the shopfront from edit cart or checkout. FIXED
  • Max values are being capped at the On Hand value in the shopfront. If stock levels go down while in the shopfront, the message window pops up, and the max value is reduced. If the on hand amount goes down in Edit cart, the max value isn’t reduced if it’s invalid, and can be carried through checkout. Rohan has plans to change this anyway, so that Max values can exceed the on hand amount.
  • Linked discourse #510 still to be done.

Testing notes April 27 @RohanM

  • NOT QUITE FIXED - Relating to #510, as I showed you if I type in a QTY in the shopfront that exceeds the on hand value for that product there’re 2 potential outcomes. a) if I keep my mouse in the QTY box for 2-3 seconds I get the ‘Reduced stock available’ message, which isn’t technically correct (the on hand value didn’t decrease) b) if i move my mouse out and onto something else I get the ‘insufficient stock available’ message dropdown, and the QTY lowers to the on hand amount that is available (this is correct). Both messages get the point across, but I suppose it’s not 100% correct in this state.
  • FIXED… if I type in QTY that exceeds on hand in the cart, when I click update, i get a message telling me there is only X on hand, and the QTY I’ve ordered automatically lowers to this value.
  • NOT FULLY FIXED - I don’t think this is a major problem, just a touch inconsistent. It could also be a good thing, because it stops customers from ignoring the red banner (in the shop they can’t ignore because they have to click somthing)…
  • Regarding the MAX value for group buy… NOT FIXED, the value is no longer held in the shopfront if I go to checkout and then return to the shop. FIXED, I’m able to type a Max value that exceeds what’s on hand. NOT FIXED - I’m able to type a max value that’s lower than the min value.

I opened an issue relate to that discussion, it’s actually a bug, it is possible to order products for more quantities than available in stock, I just did it. Ping @sstead
https://github.com/openfoodfoundation/openfoodnetwork/issues/1335