4

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).

Scenario

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.

Question

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

Setup

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
  • Code:
    • 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

Running

The user selects among the bag models

  • code
    • 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
    • user selects bag model

The user selects part to customize

  • code
    • use part-names in bag-module to get image, display the parts
  • user
    • user selects part

The user selects fabric for part

  • code
    • 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
    • user selects fabric for part

Add to cart (Once user has customized each part)

  • user
    • press Add to cart
  • code
    • 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

Checkout

  • user
    • press Checkout and finish transaction
  • code
    • Ubercart updates the stock of the fabric in the product-kit
1

Using existing modules and maybe a little custom code, you should be able to do something with a nicer workflow than your current proposed solution.

You've probably already looked at uc_stock. It tracks stock for traditional physical products nicely. By using attributes and Ubercart Stock Manager With Attributes, you can keep track of the stock of products with different attributes. For example, to sell t-shirts in sizes small, medium, and large, you give your t-shirt product the attributes S, M, and L; let the attribute alter the SKU; and uc_multi_stock will be able to track the stock of small, medium, and large t-shirts independently.

Since you want to track the quantity of raw materials, you'll need to decrement the stock of other products with the same attribute whenever an item is purchased. From the S/M/L t-shirt example, imagine you sell multiple t-shirt designs, but they're printed on demand. You have a limited number of small, medium, and large t-shirts to print on. Each time a small t-shirt is purchased, decrement the stock of all the other small t-shirts (etc).

Similarly, you'll need to set it up so that you can set the stock of all the small t-shirts at the same time.

You can either implement this using Conditional Actions or by building a small custom module that implements hook_order. I'd recommend the custom module, since that's more portable and easier to version control. If you do it in code, uc_stock_adjust($sku, $qty) adjusts the stock of $sku by $qty and uc_stock_set($sku, $qty) sets the quantity of $sku to $qty.

Happy coding!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.