重新presenting电子商务产品和变干净地在数据库中 [英] Representing ecommerce products and variations cleanly in the database

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

问题描述

我有一个电子商务商店,我建立。我使用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).

一个实体店的要求是,它需要重新present两种类型的产品:

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

  1. 简单的产品 - 这些只是一个选择的产品,如乐队的CD。它有一个基本的价格和数量。
  2. 与变化产品 - 这些都是有多种选择,如T恤,有3种尺寸和3种颜色的产品。大小和颜色的各种组合将有自己的价格和数量。
  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:

  • 拥有的产品的表,这对产品(标题等)的主要信息。
  • 拥有的的变种的表,其中包含在价格信息,为每个类型的变体。 产品 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?

推荐答案

我从事电子商务的产品在几年前,我们做到了您所描述的方式。但是,我们增加了一个层来处理对同一产品多个属性(大小和颜色,像你说的)。我们跟踪的每一个单独的属性,我们有一个单品表中所列出被允许的每个产品,每个属性的组合。事情是这样的:

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.

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

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