theUnforgiven's avatar

Help/Advise with clothing e-commerce site.

I may have asked this question before, but I'm unable to find the post I made, but here goes (again)

I have a shopping cart that sells women's clothing. The site works to the point where a item that may have many different colours and different sizes, so I need to show a dropdown with the colour and the related sizes:

Example:

Yellow size 14 top
Yellow size 16 top
Blue size 12 top

The dropdown would just show Yellow & Blue, but then upon selection it would so available colours.

I also need to be to check the stock levels as there maybe only 1 of the item therefore if it's been ordered then it would be set to 0 so that no-one else could "over" order, same is true for updating an item from within the cart, so if there's only one then it shouldn't allow multiple orders and items in the cart.

0 likes
10 replies
mstnorris's avatar

Can't this be modelled as a hasManyThrough relationship? Or even a simpler three-model pivot?

As for implementing the front-end, that's just an API call.

While checking the existence of the models themselves, look at this StackOverflow question. I can't guarantee that is the answer to your question, but might serve as a refresher at the least :)

theUnforgiven's avatar

I have a product_options table

Like this:

Then the products table

Like this:

Maybe I'm over complicating things or not thinking about it straight.

martinbean's avatar

@theUnforgiven With products like these, each variation usually has a unique SKU, so it would have its own row in the database. In your application, you could have one “parent” product (that would have a name like “Yellow Top”), and then “children” products that represent each variation.

martinbean's avatar

@theUnforgiven How have you modelling it so far? Think about the products themselves: a black size 12 t-shirt is a different product to a yellow size 8 t-shirt. Yes, you may have black t-shirts in different sizes, but they’re not technically the same product, they’re are unique, individual products.

1 like
Snapey's avatar

What @martinbean is saying is that since all items in different sizes and colours are unique (with their own stock values), what you are doing is more like filtering the items. You ought to be able to get all the products of the same family and then gradually reduce the list as more constraints are added.

So, user selects product 609. You fetch all 609s that are in stock. Then select all Distinct values of colour and all distinct values of size.

User sees two dropdowns, colour (black, raspberry, mustard, Yellow), and another dropdown with Onesize, 12-14 and 18-20

As soon as one of the dropdowns is selected, you now filter the product by that criteria. If they chose black then the size box shows the only option 'One size'. If they choose yellow then the size dropdown shows two choices.

If, on the otherhand, they first select One Size, then the colour box changes to black, raspberry, mustard, removing the yellow.

(here I am assuming all variations in stock)

You could do this client side if the number of items is small (say, 200), or do an ajax call on each change of filters.

The benefit of ajax calls is that if another shopper is closing a transaction you can remove items that are no longer in stock.

1 like
theUnforgiven's avatar

@Snapey yeah just thinking how I can get around this without changing too much code and database entries.

frezno's avatar

@theUnforgiven i'd strongly recommend to change it and do it right. If not it's just a matter of time you'll end up in a desaster. But then you might have already 300+ products.

You need a table for the product and each single product has to have its own, unique SKU (as @martinbean already mentioned). Then you need an options table with all the product attributes listed as colors, sizes, material, etc. And as a third table you have to have a lookup (pivot) table, bringing it all together.

theUnforgiven's avatar

Yeah agreed that it is going to have to be that way it looks so a bit of work i guess but then at least ita will be right

Please or to participate in this conversation.