简体   繁体   English

电子商务产品过滤器db设计

[英]E-commerce product filter db design

I'm creating an e-commerce site and my products are grouped in categories (like in any other e-commerce system). 我正在创建一个电子商务网站,我的产品按类别分组(如任何其他电子商务系统)。

The problem is the following: different categories (and products in it) need to have different attributes (like TV's smart tv or not). 问题如下:不同类别(及其中的产品)需要具有不同的属性(如电视的智能电视与否)。

So someone could help me with some product filtering "theory" (db design) what are the good practices to follow? 所以有人可以帮助我一些产品过滤“理论”(数据库设计)有哪些好的做法可以遵循?

And how can I "build" these product category pages automatically (to build up automatically the filters for ex.: in the TV category a switch for smart tv or not and in Phones category smart phone or not ). 我如何自动“构建”这些产品类别页面(自动构建过滤器,例如:在电视类别中是否为智能电视或智能电视的开关以及电话类别的智能手机)。

Thanks for the help! 谢谢您的帮助!

Most ecommerce systems use a Category tree with infinite levels. 大多数电子商务系统使用具有无限级别的类别树。

Then when editing your product you show that tree with checkboxes and you click on the checkboxes of the categories you want to assign this product to. 然后,在编辑产品时,您会显示带有复选框的树,然后单击要将此产品分配到的类别的复选框。

For this you will need the tables: product, category, and category_has_product. 为此,您将需要表:product,category和category_has_product。 So when you check the boxes all these categories should be inserted to category_has_product for that product. 因此,当您选中复选框时,应将所有这些类别插入到该产品的category_has_product中。

Then when searching you join product with category_has_product, quite simple. 然后在搜索时使用category_has_product加入产品,非常简单。

Otherwise if you want users to be able to choose only one single category from the end of the Tree, but you want to be able to filter products inside a parent category and include the ones in the children you could take a look at stuff like this, it's more complex to understand but maybe you find some other examples on how to implement it: 否则,如果您希望用户只能从树的末尾选择一个类别,但您希望能够过滤父类别中的产品并将其包含在子类中,您可以查看这样的内容,理解起来比较复杂,但也许您会找到其他一些如何实现它的例子:

http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

The point with nested categories is that you could end up storing only the final category_id on the product table but even so you will be able to do some magic to include that product in the search results of all the parent categories. 嵌套类别的要点是,您最终只能在产品表中存储最终的category_id,但即便这样,您也可以将所有产品包含在所有父类别的搜索结果中。

So the above would cover the "how to manage products into categories". 因此,上述内容将涵盖“如何将产品分类”。

As for links: Well you could just loop inside the category tree and print the links where you want and how you want. 至于链接:你可以在类别树中循环并打印你想要的链接和你想要的方式。

As for additional filters such as Type of TV (Smart or Not) you could either just include both inside the categories tree and forget about adding additional fields to the product form or you could have a more complex solution using something like attributes: 至于其他过滤器,例如电视类型(智能或非智能),你可以只将两者都包含在类别树中,而忘记在产品表单中添加其他字段,或者使用类似属性的东西可以使用更复杂的解决方案:

You would have table attributes (id, name) and table attributes_value(id, attribute_id, value) then on the product form instead of having static checkboxes for "This tv is Smart", you would loop into the attributes table, and you have a attribute named "Smart Tv", and the values would be "Yes, No, Maybe, etc", so you use that to draw dynamic dropdowns. 您将在产品表单上拥有表属性(id,name)和表attributes_value(id,attribute_id,value),而不是具有“This tv is Smart”的静态复选框,您将循环到属性表中,并且您有一个名为“智能电视”的属性,值为“是,否,可能等”,因此您可以使用它来绘制动态下拉列表。

Now if you also want links for the attributes, well you just create a link to a category and to a specific attribute with a specific value. 现在,如果您还需要属性的链接,那么您只需创建一个指向类别和具有特定值的特定属性的链接。 Example /category.php?id=2&attribute=1&attribute_value=5 示例/category.php?id=2&attribute=1&attribute_value=5

Also if you want to have some seo-friendly urls, just add a "slug" field into both category table and attribute_values table and then rewrite the urls. 此外,如果您想要一些seo友好的网址,只需在类别表和attribute_values表中添加“slug”字段,然后重写网址。

You could also take a look at Prestashop, it uses or used some of the things discussed here even if now it grew very complex and quite pain in the ass but might provide some useful information. 你也可以看看Prestashop,它使用或使用了这里讨论的一些东西,即使现在它变得非常复杂而且非常痛苦,但可能会提供一些有用的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM