theUnforgiven's avatar

Building small e-commerce platform, need a little help.

Hi All,

I'm building a small e-commerce platform with Laravel and all is well, but I have an issue.

My client sells clothing and she can sell for example: A dress that she has in 4 different sizes 8, 10, 12, 14 Along with different colours black, white, green. So my question is how is the best way to control stock for this?

I have a table for products like so: http://f.cl.ly/items/1B3W3D2W2b0z0S1i3R19/Screen%20Shot%202014-10-30%20at%2015.00.08.png

And I json_encode when creating a product within the cms then json_decode on the front end to show like this: http://f.cl.ly/items/2z3P35300M2H3H2T171J/Screen%20Shot%202014-10-30%20at%2015.01.31.png

Which works fine ,but obviously I need it to take of stock for whichever product is order, so say I ordered a black size 8 size (not that I would!) then that needs to be reflected in the stock within the CMS, how can this be done???

0 likes
7 replies
cipsas's avatar

You should create separate table for product variants.

cipsas's avatar

One table for products, columns: id, name, seo_title, description end etc. Other table for product variants: id, product_id, option1, option2, price, stock_quantity end etc.

When product variant is ordered, decrease stock_quantity

alexhiggins's avatar

You would have a parent table and a child level - child would be responsible for the variants. So, 8Black is one product, 8White is another.

I'd have stock in another table which would join on your child level table

I'd have prices in a different table because of things like price breaks. Plus things like RRP, sale price. You're assuming a product would have one price - I wouldn't store it as varchar either.

I'd have your slug, seo stuff in your parent table too.

I would also have the descriptions in another table and that would usually be done at parent level. (child titles are usually pointless but you could have it)

I would not have them called size and colour tables too. That's a bit too specific, You would want something like an attribute table that would store Size + Colour

I would also have your images in another table too as you might have more than one image for the product as you would have thumb + zoom etc then maybe a default image with other ones.

theUnforgiven's avatar

So quite a bit of tweaking to do then I guess, cool I understand now which is kinda what I thought but wanted more heads sharing there views.

tios's avatar

I use a single table for all kind of products. A column "child_of" tells the system how to handle the item.

All attributes are stored in two tables. Attributes and values. So I can have as much attributes as I need. Size, colour, material and so on.

A last table contains information about the select-boxes the shop should create for a specific product.

I hope my English is good enough to understand what I talk about ;)

Please or to participate in this conversation.