Update product quantity after order

Hey guys.

I am currently working on a marketplace but I cannot update the stocks when a new order is placed. I have 3 data types :

1. Product
Products added by store owners.

2. Ordered product
This includes a single ‘product’ + additional fields (quantity etc). Created by users when they add a product to their baskets.

3. Order
This includes a list of ‘Ordered products’ + additional fields

Basic workflow is :

1 A customer adds products to his basket
2 New ordered products are created and added to his current order
3 the customer pays and a new order is placed.

So, I have a list of ordered products in my cart, and each of them has its quantity. When the order is placed, I would like the quantity of each products from oredered products in the cart to be decreased by the amount of the ordered product quantity that contains current product.

It would be really cool if someone could help me, I’ve been stuck on this for several days. Thank you so much !

Hi
Use like below for updating the stock,

stock = this product’s stock - parent group’s order’s ordered products’s :filtered (product = this product) quantity

Hi @mani2726 and thanks for your answer,

I just tried, unfortunately it doesn’t work…

I had tried something similar yesterday, telling myself that the logic behind would be to decrease the amount of the oredered product that contains the product but I always failed.

:weary:

Update : the last sentence (quantity) is evaluated to a list of numbers. Maybe this will help
Update 2 : added :first item at the end of sentence. Sentence is correct, but not working. Quantities are not updated…

Stock = This Products’s Stock - Parent group’s Order’s Ordered products: filtered :first item 's quantity

This should do the trick!

Basically what you need to do is set the “:first item” after the filter - as the filter returns "a list of products.

I have the same issue. This way only it update the first one item