S
S
sugarufc2015-05-10 21:28:21
PHP
sugarufc, 2015-05-10 21:28:21

How to correctly implement clothing sizes for an online store in the database and PHP?

Please do not judge strictly, I'm just learning, there may be errors in the wording of the question, but I will try to convey the essence.
I'm trying to create an online store and then I ran into a problem.
There is one product (for example, a T-shirt) in the database with different sizes (for example, S, M, XL).
1) How to properly develop the database structures for this product, so that in the future it will be easier to display the product on the page and the user can manipulate with the sizes, i.e. choose any size of this product:
- first I did this: 3829d3a9e7d546eabd3a4c9181c1085f.jpg
- then like this: 023a752ffb154d1abce945a3fdb03433.jpg
but something I don't really like those options. How do many online stores actually do this structure so that everything is displayed correctly in the future? Or tell me who knows how it will be more correct.
2) How to correctly display the product on the page? For example, like here (photo): (link: www.ozon.ru/context/detail/id/31921559/?item=31920956 )
e24f0e69e0044f01b1fa3059da166447.jpg
When choosing a size and adding to the cart, I get one size, but when I want to add the same product only of a different size, then the last item simply replaces the previous one, and I need two identical items in the cart, but with different sizes.
PS I apologize if I illiterately stated the essence of the problem, but who understood, please help. Or at least tell me where to go, then I myself. Thank you.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
R
Rsa97, 2015-05-10
@Rsa97

The main table of goods by article
Table of balances by size (article, size, balance)
When adding to the cart, the quantity is summed up by pair (article, balance)

F
Fedor Ananin, 2015-05-22
@sarathorn

Did this, a lot of hemorrhoids. Stopped on a variant with three tables.
table items:
item_id | name | price and so on...
table options:
id_options | option name | impact on price
table items-options:
item_id | id_options separated by commas | bundle name
Thus, we load basic information from items, we load items-options, we get something like this from there:
1 | 1,2,3,4 | Color
This means that product 1 has the ability to choose a color...
We load options with IDs 1,2,3 and 4. We get, for example:
1 | Red | 0
2 | Blue | +100
3 | White | -20
4 | Black | 0
This means that a product with red and black color will cost the base price, blue color is 100 rubles more expensive, and white is already 20 cheaper.
Add everything to the cart in the following format:
product_id | id_of_selected_options_separated by_commas | quantity
If a visitor adds a product 1 of two different colors, then there will be two entries in the cart:
1 | 1.2 | 1
1 | 3.4 | 1
Options can be combined. In my case, these were interior doors, it was necessary to take into account the size of the leaf, color and the presence of basic accessories (hinges, handles, trims, etc. ..). Accordingly, if a visitor needs a door 200x100cm and the same 190x90cm, then it is more reasonable to present it in the basket as two different goods. This way he can safely order two doors of the first size and, say, seven doors of the second size.
I understand that in some sense my implementation is a crutch, but it works and works very simply.

S
Sergey, 2015-05-10
@serega_kaktus

There are many options, it all depends on what other features are tied to the "size" parameter. I saw in stores and as your first option - but then when adding a product to the cart, you need to compare not only the product id, but also the size so that there is no substitution. I also saw your second option - on the one hand, it is flexible, you can add different features, on the other hand, it is a bit overcomplicated.
You can also create a size table and a product-size table, while adding a product and a record from the product-size table to the map so that they are unique.

R
Roman Hinex, 2015-05-10
@HiNeX

You can do this: the subproduct is the color, the additional attribute is the dimensions (you can make a multiselect in the admin panel and write an array of the selected sizes to the admin panel, for example, via serialize() in one field to the subproduct.

R
Remsin, 2015-05-10
@Remsin

On the first question: in this case, the dimensions should be taken out in a separate relation and associated with the "Clothes" relation. Those. create another table - "sizes" (information about all sizes will be stored there) with attributes - id and size names. And in the existing table "clothes" add a new attribute "sizes_id" and make it a foreign key from the table "sizes".

I
Igor Vorotnev, 2015-05-11
@HeadOnFire

Standard approach:
1 Table - product and its standard characteristics
2 Table - additional characteristics (colors, sizes, dimensions, availability / stock, etc.)
3 Table - links between the first 2 tables
Selecting from these tables using LEFT JOIN / INNER JOIN, for example .
There is also an intermediate table "types of links", then in table 2 only the options themselves and the foreign key on the ID field from the table "types of links" are stored. That is, T1 - goods, T2 - types of links (color, size, weight, availability, etc.), T3 - characteristics (all options for colors, sizes, etc.), T4 - links. Such schemes occur, but, IMHO, rarely make sense. The standard model is usually sufficient.

A
Alexey Ivanov, 2015-05-11
@Sphinx123

Completely agree with Remsin. Make a second table with the size (id, sizes, count, etc.) and link it to the main one.
Sampling from a DB through dzhoin, we will admit. You can make it so that when you click on the order, the order is entered in the basket and the number of the selected size is reduced in the size table. This is offhand, in more detail, I think you will finish it yourself. Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question