Saving, organizing and querying products, options / tags and categories

First of all, let me make it clear that I am not asking for any code; I just don’t know any general ideas / recommendations / opinions on how I can implement what I am going to ask.

I am starting to build an online e-commerce system (Yii2 + MongoDB, like PHP + NoSQL), and there are two details that I’m not quite sure how to implement without creating a huge mess in both my code and database.

Both details are related to each other, so I will explain them as one.

Like any other serious e-commerce, it would have categories. And also, like any other serious e-commerce, each product will have tagsor options. Let me explain a little what I call tags/ options.

These are the available options that the user could choose when purchasing a product, for example, color or size, material, etc.

  • Categories

There would be several categories general, as well as other subcategories. For example, it Electronicsmay be a general category, and subcategories will be Computersand Smart TVs. Then Motherboardsthey RAMcan be subcategories Computers.

This in itself can easily be stored in a database, but here is the problem:

  • Each product should appear when listing any of the categories to which it belongs, or to the upper categories. This means that if I (as an end user) look through all the elements of a category Computers, I should see NVIDIA GTX670which one belongs to a subcategory of the Graphic cardscategory Computers.

I could save each product as follows:

{
    _id: asdasfwetrw34tw34t245y45y,
    name: "NVIDIA GTX670",
    price: 99.50,
    ...
    ...
    categories: [
        "Electronics", //<-- just the ID of that group
        "Computers", //<-- just the ID of that group
        "Graphic cards" //<-- just the ID of that group
    ]
}

But:

  • , (, , ).
  • , , , , .


2. /

.

0 , Woman fashion size color, Sunglasses ( Woman fashion) color , Woman fashion.

, (red, green, blue color) . , Woman fashion , Strawberry Red Tangerine, Cars - Carbon Black metallic.

, :

  • (, size, S M), . custom size, Kind of small, , ).
  • Static, (, colors, red green, , ).
  • (, dimensions weight), . [10] | (mg||kg|tons) [20] (cm|m|km|miles)).


:

{
    option: "Color",
    type: "Static with combinations"
    values: [
        {
            value: "Red",
            categories: [
                "Sunglasses"
            ]
        },
        {
            value: "Green",
            categories: [
                "Sunglasses",
                "T-Shirts"
            ]
        },
        {
            value: "Black metallic",
            categories: [
                "Cars"
            ]
        }
    ],
    categories: [
        "Woman fashion", //<-- only the ID of this group
        "Cars" //<-- only the ID of this group
    ]
}

, , 30 , .
, , , .

, , -, , , .

+4
1

. , . , .

, :

    {_id: 1, name: "Electronics", parentId: 0, idPath: "/0/1/" ...}
    {_id: 2, name: "Computers", parentId: 1, idPath: "/0/1/2/", ...}
    {_id: 3, name: "Graphic Cards", parentId: 2, idPath: "/0/1/2/3/", ...}

. :

    {
        _id: asdasfwetrw34tw34t245y45y,
        name: "NVIDIA GTX670",
        price: 99.50,
        ...
        ...
        categoryIds: [3]
    }

, , categoryIds . . Electronics, :

    db.categories.find({idPath: /^\/0\/1/})

idPath index , . , ( categoryIds Product).

, , - - > categoryId, value → [ ]. , . , .

  • /Options

, , - . Women fashion - , , . , coat, size color, Women fashion. Women fashion color, .
, ? - . . . :

: | -:
| -sun glasses: shape

coat, , 2 color size. sun glasses: color shape. Women fashion, 1 color. , Women fashion.
, Strawberry Red red, Tangerine orange. , . , .
, color , -, customizable options. . . Strawberry Red Tangerine. , "" . . , , Tangerine with figure ..
. , . , color . dimension .

. , . , Number, String, Single Choice, Multiple Choices. Unit. Unit , , ,

1GB = 1024MB = 1024*1024B

, 1 1 , . , .

, , . . Material of coat Furniture - . . , color toys color Women fashion. , . , . , . , .

, . , , , . , .

+5

All Articles