Shopping cart impossible if quantity exceeds stock

Hello, I need your help, I’m stuck.
On my store I have variable products with a quantity. I don’t want it to be able to proceed to payment if the quantity is greater than the stock.

I’ve managed to display text if this is the case in the repeating group, but I want to apply a condition to the payment button.

The shopping cart is a list of items that includes a product lot and a quantity. My lot also has a stock quantity.

Thanks for your help.

Capture d’écran 2024-09-03 à 17.06.18

Hi, in your case one solution is to use a custom state and some workflows.

  1. Create a custom state (e.g. “validationPayload”)
    • type: text
  2. On loading set state to RG list of products: format as text
    • content to show per item: product’s unique id: false
    • delimiter: |
  3. Create a workdflow when dropdown in RG is changed
    • when dropdown value > quantity available, set state to index validationPayload
    • new value: index’s validationPayload:find & replace
    • text to find: parent’s group unique id: true
    • replace by: parent’s group unique id: false
  4. Create a workdflow when dropdown in RG is changed
    • when dropdown value < or = quantity available, set state to index validationPayload
    • new value: index’s validationPayload:find & replace
    • text to find: parent’s group unique id: false
    • replace by: parent’s group unique id: true
  5. setup conditional on the pay button:
    • when index’s validationPayload contains “false”
    • this element is not clickable
    • change background color or do not display it as you wish

This should work. hope this help :slight_smile:

Thanks for your help, I will try this !

You might be directly using the data, which can make it challenging to manage quantity or stock-related issues.

A better approach would be to create a separate Checkout item and include it in your Cart table.

If the quantity of any item in the cart exceeds the available stock, you can display an error message, preventing the item from being added to the cart.

This method is used by most online shops and avoids blocking the checkout buttkn, which is not very user-friendly.

You may need to reorganize your database structure to implement this.

1 Like

This app of ours might be a good example