Question

I have a situation:

I have products that are in a CodeIgniter Cart custom store. Each product has an ID associated with it, but also has options for it (sizes). These sizes all have different prices. (We're talking about photos being sold at different print sizes).

Because CI Cart updates, adds and deletes based on the product ID inserted, I am not able to insert one product with 2 different sizes. As of now, the only solution I can think of is to pass the ID to the cart as IMAGEID_OPTIONID so that it contains both IDs.

However, I thought there might be an easier, more uniform way of doing this? Or a better solution than an ID that isn't (on it's own) associated with anything specific unless i explode it..?

Was it helpful?

Solution

I recently built a site that had these constraints. In short, you'll want to create a distinction between "products" and "product groups". Think of it as managing the most discrete data units. In reality, shirt X sized medium is actually a different thing than shirt X sized large...doubly so if you have prices that are built on these qualities (this becomes more realistic when you consider cloth patterns or colors).

So anyway, if you have a "groups" table, a "product_groups" table, and a "products" table, you can keep all of these ideas distinct. On your products table, you can have columns for "size" and "color" (and any other distinguishing property you can think of) and a column for "price". Alternatively, you can go even more hardcore and make separate pricing tables that match up prices to unique products (this would be especially useful if you want to keep track of historical prices and discounts).

Then in your cart you can simply attach product_ids to cart_ids and perform a couple of joins to determine what "group" this product is a part of, what pictures are in that group (or exist for that product), and so on. It's not a simple problem, but following this line of thought should help get you on the right path.

One last point: keeping track of unique products like this also makes inventory accounting much, much more straightforward.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top