Blog | Master and slave items – keeping stocks up to date
3rd September 2013
We recently came across an interesting problem whilst working on our new Client’s ecommerce project whereby item A is made up of multiple quantities of other items, lets call these X and Y. How can we ensure we are keeping stock quantities up-to-date? Usually, the stock levels are stored and updated on a per product basis:
- Item A: 10 in stock
- Item B: 5 in stock
- Item C: 8 in stock
Commerce Products are never that simple
But what if item A was made up of 10 item X’s and 5 item Y’s? How could we update the stock levels for items X and Y if item A was purchased? Well, this definitely got us thinking and we came back with all types of solutions! In the end we decided to go with what we called “Master Products” which were assigned only a stock level and product code.
The first thing we integrated was a new section within the Shopit admin that enabled the Client to create and manage their master items themselves. To keep things as simple as possible, they only need to enter the main information, with the stock level being the key field.
We then added extra functionality to the existing edit item/edit child page in the admin so these master products could be attached to existing inventory products. Because not all products in the inventory would have an attachment to master items, we had to give the option to turn these on and off when required. Finally, we adjusted the store-front to update the correct stock level on successful purchases.