cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fallen
New Member

Shopping Cart - Update Product Stock

Good morning, I was hoping someone could point me in the right direction here.

 

I have created a shopping cart app with various items with a column which provides the current stock of an individual item, I am using sharepoint as a datasource (Shopping Items). The items get added to a collection (CartOrders) with the quantity of that item. Both these sharepoint lists share the same ID throughout.

 

Moving onto the checkout screen. There is an option to change the quantity and finally a submit button on there which populates a blank sharepoint list (CartOrderedItems).

 

Is it possible to update the product stock on the Shopping Items sharepoint list once they press the submit button with whats populated in the CartOrders collection?

 

Hopefully this makes sense. If there is anything else which will help in this matter, please let me know.

 

Thank you for your help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @v-xiaochen-msft,

 

Many thanks for your assistance in this matter.

 

I did spent sometime messing around to find a soultion before I came back here. In the end I believe I found one that does the job.

 

Below is a collection I use to store all the information as the customer goes along.

 

Collect(ShoppingItemsOrdered, { ProductImage: ThisItem.'Product Image', ProductID: ThisItem.'Product ID', ProductName: ThisItem.'Product Name', ProductPrice: ThisItem.'Product Price', ProductQuantity: QuantityValue.Selected.Result, ProductTotalCost: (ThisItem.'Product Price' * QuantityValue.Selected.Result), ProductNewStock: ThisItem.'Product Stock' - QuantityValue.Selected.Result }));

 

As with the way I've built the cart is they can add more items each time they add a new quantity. But the end is that it'll store the new stock until they are finished with the order.

 

ProductNewStock: ThisItem.'Product Stock' - QuantityValue.Selected.Result

 

When the customer then clicks the submit order button I added the following code:

 

ForAll(ShoppingItemsOrdered, UpdateIf('Items - Spirits', 'Product ID' = ProductID, {'Product Stock': ProductNewStock}));

 

As far as I can tell the stock updates on the orginal item list without any errors so far.

 

Once again thank you for your help.

 

View solution in original post

2 REPLIES 2
v-xiaochen-msft
Community Support
Community Support

Hi @Fallen ,

 

Could you tell me:

  1. Do you have two lists? (One is ‘shopping Items’ andthe list stores all products and their inventory quantities. The other one is ‘CartOrderedItems’ and this list records the user's shopping information. )
  2. Do you want the user to create a new shopping record in the ‘CartOrderedItems’ list after pressing the submit button? And do you want to subtract the quantity in the submitted record from the product inventory quantity in the ‘shopping Items’ list?

 

If my assumptions are correct, I've made a test for your reference:

 

1\ This is my list ‘Shopping Items’. ‘Product’ is a Single line of text column. ‘Quantity’ is a number column.

v-xiaochen-msft_0-1613372107754.png

 

 

2\ This is my list ‘CartOrderedItems’. These columns are all number columns.

v-xiaochen-msft_1-1613372107756.png

 

 

3\ Add a gallery control and set its Items property to:

'Shopping Items'

 

4\ Add 3 textinput control ‘TextInput1’ ,‘TextInput2’, ‘TextInput3’.

 

5\ Add a button control and set its onselect property to:

Patch(CartOrderedItems,Defaults(CartOrderedItems),{Title:"test",Apple:Value(TextInput1.Text),Banana:Value(TextInput2.Text),Orange:Value(TextInput3.Text)});
Patch('Shopping Items',LookUp('Shopping Items',Product="Apple"),{Quantity:LookUp('Shopping Items',Product="Apple").Quantity-Value(TextInput1.Text)});
Patch('Shopping Items',LookUp('Shopping Items',Product="Banana"),{Quantity:LookUp('Shopping Items',Product="Banana").Quantity-Value(TextInput2.Text)});
Patch('Shopping Items',LookUp('Shopping Items',Product="Orange"),{Quantity:LookUp('Shopping Items',Product="Orange").Quantity-Value(TextInput3.Text)})

 

6\ The result is as follows:

v-xiaochen-msft_2-1613372107758.png

 

v-xiaochen-msft_3-1613372107759.png

 

v-xiaochen-msft_4-1613372107760.png

 

 

Since this is a broad problem, I have given one of the solutions.

 

Best Regards,

Wearsky

If my post helps, then please consider Accept it as the solution to help others. Thanks.

Hi @v-xiaochen-msft,

 

Many thanks for your assistance in this matter.

 

I did spent sometime messing around to find a soultion before I came back here. In the end I believe I found one that does the job.

 

Below is a collection I use to store all the information as the customer goes along.

 

Collect(ShoppingItemsOrdered, { ProductImage: ThisItem.'Product Image', ProductID: ThisItem.'Product ID', ProductName: ThisItem.'Product Name', ProductPrice: ThisItem.'Product Price', ProductQuantity: QuantityValue.Selected.Result, ProductTotalCost: (ThisItem.'Product Price' * QuantityValue.Selected.Result), ProductNewStock: ThisItem.'Product Stock' - QuantityValue.Selected.Result }));

 

As with the way I've built the cart is they can add more items each time they add a new quantity. But the end is that it'll store the new stock until they are finished with the order.

 

ProductNewStock: ThisItem.'Product Stock' - QuantityValue.Selected.Result

 

When the customer then clicks the submit order button I added the following code:

 

ForAll(ShoppingItemsOrdered, UpdateIf('Items - Spirits', 'Product ID' = ProductID, {'Product Stock': ProductNewStock}));

 

As far as I can tell the stock updates on the orginal item list without any errors so far.

 

Once again thank you for your help.

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,869)