I have a scenario where I have an idea of how to solve it but I want to be sure that I am not making it more complicated than it has to be. I am new to Ubercart and Drupal in general (but experienced in software development / databases).
Generalization: need to manage stock levels of raw materials which a user can select among to build a product and order the product. The specific scenario follows below.
On the site the user can customize bags. Specifically each model of a bag is divided into four parts. The user may choose a specific fabric for each part - but which fabrics to choose from depends on the model.
An example. A user may select among fabric A,B,C,D for parts in bag1 and among fabric C,D,E,F for bag2.
It is required to manage stock at fabric level, but the cart should only show the final customized bag level.
So if enough orders are made of bag2 with fabric C so that it runs out, then the option fabric C should no longer be available for bag1.
It seems to me it is not possible to accomplish the above straight in Ubercart, so my idea is to use an auxiliary database. But perhaps it can be done with configuration and/or some additional module - my first question is whether it could somehow be possible to configure this without having to do code customization / additional database.
I am planning to create a specific module where the user can choose bag-model, and then proceed to choose fabric for the parts and have the bag displayed as it is currently customized.
My second question, assuming that an additional database is required, is the below solution a good solution or is there perhaps a way which would require less work?
Possible solution (new)
EDIT: This is a way to not have to rely on an auxiliary database outside of Drupal.
- use a product class to represent Fabric-Products, each Fabric-Product is just a piece of fabric
- use a product-kit to represent a Customized-Bag
- use a product class to represent Bag-Model which represent a particular model. Note, it is not customized, fabrics has not been chosen.
- use a product class Bag-Model-Part which has one node reference to one Bag-Model, so these specifies which parts exists per bag. It also has a list (node reference) to Fabric products, these are the possible Fabrics among which one can be chosen for the part
- use a product class to represent Bag-Part-Fabric, which has a node reference to a Bag-Part and to one Fabric (so it is a particular configuration, there one specific fabric has been chosen for one specific part). It also has an image which shows how the part looks like with that fabric.
- the Customized-Bag product kit has a set of Bag-Part-Fabric which specifies exactly how that bag is to be customized, and it also has the set of Fabric used - so that the stock level of the Fabric goes down when it is ordered. It has one image which shows how the final bag looks like.
With this idea, the number of product kits will be PLENTY and so I would have to generate these by code. The manager of the site can easily manage using Drupal the Fabric, Bag-Model, Bag-Model-Part. A bit more tedious but possible for the site-manager is to also add the Bag-Part-Fabric. So the code to generate the product kits can find this data in Drupal, fetch the images from the Bag-Part-Fabric to generate the final image for each product kit.
I assume the code to generate the product kits would be a module which the site manager can trigger to run every now and then (after a batch of new bag-part-fabrics has been created).
The flow for a user visiting the site to customize a bag is: # choose one of Bag-Model # for each Bag-Model-Part with that Model, choose one Fabric among possibles and in stock # once all parts have a chosen fabric, I have the set of Bag-Part-Fabric, use these to find the particular Customized-bag product kit # when/if user adds to cart, then put the Customized-bag product kit in the cart
Is this an OK solution? Is there something easier or better?
Possible solution (old)
Idea on how to solve the scenario using Ubertcart and an auxiliary database.
Create a Product Class for: fabric and bag-model
Create a Product Kit for: bag There bag is a final configuruation (e.g. 630 bags if 3 models, 10 fabrics, 4 parts)
Create a non-Drupal auxillary database:
- links SKU of a bag-model to allowed fabric SKU per part
- links SKU of a bag to the specific fabric SKU in that bag configuration
By owner of site
- enters (some) unique id for each bag model and the parts of the bag
- enters (some) unique id for each fabric
- enters the allowed unique id of fabric per part per bag model
- generates SKU per bag model and per fabric
- use Ubercart API to create all bag-model products
- use Ubercart API to create all fabric products
- use Ubercart API to create all bag product-kits (all possible combination of fabric)
- write to auxillary db, for each bag-model, link fabric SKU to part in bag-model
The user selects among the bag models
- from Ubercart, get all bag models
- display all bag models
- (perhaps not display bag model if all fabric for all its parts is out)
- user selects bag model
The user selects part to customize
- use part-names in bag-module to get image, display the parts
- user selects part
The user selects fabric for part
- from auxillary db, get fabric SKU allowed for part-nr, using the choosen bag-model SKU
- from Ubercart, for each fabric SKU check if is in stock
- display fabric SKU allowed for the part and which is still in stock
- user selects fabric for part
Add to cart (Once user has customized each part)
- press Add to cart
- from auxillary db, get bag-product kit using the fabric SKU selected per part and the bag-model
- using Ubercart API, add the bag-product kit to the cart
- press Checkout and finish transaction
- Ubercart updates the stock of the fabric in the product-kit