在数据库中清晰地表示电子商务产品和变体 [英] Representing ecommerce products and variations cleanly in the database

查看:18
本文介绍了在数据库中清晰地表示电子商务产品和变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建设一家电子商务商店.我正在使用 Rails/ActiveRecord,但这真的没有必要回答这个问题(但是,如果您熟悉这些东西,请随时以 Rails/AR 的方式回答).

I have an ecommerce store that I am building. I am using Rails/ActiveRecord, but that really isn't necessary to answer this question (however, if you are familiar with those things, please feel free to answer in terms of Rails/AR).

商店的要求之一是它需要代表两种类型的产品:

One of the store's requirements is that it needs to represent two types of products:

  1. 简单产品 - 这些产品只有一种选择,例如乐队的 CD.它有一个基本的价格和数量.
  2. 变化的产品 - 这些产品有多种选择,例如有 3 种尺寸和 3 种颜色的 T 恤.每种尺寸和颜色的组合都有自己的价格和数量.
  1. Simple products - these are products that just have one option, such as a band's CD. It has a basic price, and quantity.
  2. Products with variation - these are products that have multiple options, such as a t-shirt that has 3 sizes and 3 colors. Each combination of size and color would have its own price and quantity.

我过去做过这种事情,并做了以下事情:

I have done this kind of thing in the past, and done the following:

  • 有一个 products 表,其中包含产品的主要信息(标题等).
  • 有一个 variants 表,其中包含每种类型的变体的价格数量信息.产品 have_many 变体.
  • 对于简单的产品,他们只会有一个相关的变体.
  • Have a products table, which has the main information for the product (title, etc).
  • Have a variants table, which holds the price and quantity information for each type of variant. Products have_many Variants.
  • For simple products, they would just have one associated Variant.

有没有更好的方法可以做到这一点?

Are there better ways I could be doing this?

推荐答案

几年前我从事电子商务产品的工作,我们按照您描述的方式完成了这项工作.但是我们又增加了一层来处理同一产品的多个属性(尺寸和颜色,就像你说的).我们分别跟踪每个属性,我们有一个SKU"表,列出了每个产品允许的每个属性组合.像这样:

I worked on an e-commerce product a few years ago, and we did it the way you described. But we added one more layer to handle multiple attributes on the same product (size and color, like you said). We tracked each attribute separately, and we had a "SKUs" table that listed each attribute combination that was allowed for each product. Something like this:

attr_id   attr_name  
1         Size  
2         Color  

sku_id    prod_id    attr_id    attr_val  
1         1          1          Small  
1         1          2          Blue  
2         1          1          Small  
2         1          2          Red  
3         1          1          Large  
3         1          2          Red  

后来,我们添加了库存跟踪和其他功能,并将它们与 sku ID 绑定在一起,以便我们可以单独跟踪每一个.

Later, we added inventory tracking and other features, and we tied them to the sku IDs so that we could track each one separately.

这篇关于在数据库中清晰地表示电子商务产品和变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆