How to update quantity when an order is made

Alex, I've been trying to learn and build my own application for a couple months now and some of the concepts you cover in the platform tutorial is probably the best on the internet! Thanks a lot. So I am trying to do a similar thing as what youre doing with the etsy demo but want to add a fixed quantity for some of the products. What is the best way of going about that?

Posted over 3 years ago by Andrew Selvadurai
Posted over 3 years ago by Alex Yang

Thanks Andrew! The approach is largely the same, with only a couple deviations.

You'll need to make sure your app knows how many of each Listing is available when the Listing is first created. So you'll want to create a migration to add a new field (e.g. 'inventory') to your Listings table. Make sure that you update the values for 'inventory' for any of your existing Listings.

You'll also need to allow Users to choose how many of a given Listing they want to purchase, up to the 'inventory' available. So you'll want to create a migration to add a new field (e.g. 'quantity') to your Orders table. The calculation of the price of their Order will also need to change to reflect the quantity purchased.

Finally, after an Order is placed, you'll need to update the 'inventory' remaining for that Listing.

Hope that helps!