Update product quantity in database after a customer purchase

Hey gang,

I’ve built a simple e-commerce platform. Store owners can currently upload products but aren’t yet able to include a quantity (stock level), so here’s what I’m trying to achieve (e.g):

  1. A store owner has 10 units of a product available
  2. A customer buys 5 units
  3. Store owners product is automatically updated with new stock level (5)

I have a couple of data types going on here:
1. Product
A single product.

2. Basket item
This includes a single ‘product’ + additional fields (quantity etc)

3. Order
This includes a list of ‘basket items’ + additional fields

I feel like I need to subtract the ‘basket item’ quantity from the ‘product’ quantity but I only want to do this once the ‘order’ has been created because that’s when a customer has actually paid.

Does that make any sense?

I would reserve the 5 as not available once the customer has placed it in their basket.

As far as the actual subtraction goes, it depends if there is a scenario where the order can be canceled or changed. If this is possible, then I would only do the actual subtraction once the order is fulfilled.

The rule here is that your system quantity must always match your physical quantity.

@SerPounce Really appreciate the input :slightly_smiling_face: any thoughts on how I could achieve the subtraction after purchase, based on my current setup?

I’m not sure what you’re specifically asking here. The generic answer is:
Product type quantity = Product type quantity - basket quantity

But I’m guessing there’s more to your question than that.

@zack.strubel Have you been able to solve this? I’m also having a similar problem. In my case I have a list of items in my cart, and each of them has its quantity. When the order is placed I want the quantity of each item in the cart to be decreased by the amount of that item sold.
Can anybody help with the workflow example? :slight_smile:

Hi @annae.novikova Yes, I was able to find a really hacky way to achieve it for my use case. It was a total headache and unfortunately, there were so many steps that I honestly can’t remember how I did it.

The basic idea was:
Product quantity - order quantity = updated product quantity

The difficult part for me was that I am operating as a marketplace, so have multiple shops with multiple customers who are buying multiple products.

Sorry I can’t give more detail but I hope you find a way. Bubble is totally trial and error. Just keep trying and you will find a way :slight_smile:

Hey @annae.novikova, did you solve this ? I’m in a similar case and can’t find any solution

Hey, @_nathan yes, by running a backend workflow on a list of sold items, following @zack.strubel 's advice.
My solution turned not to be the most elegant solution, but it worked :slight_smile: