我即将制作一个在线电子商务网站,用于销售一些产品,如鞋类、服装等。但是,我无法理解如何设置该模式(表和所有表)。我是用 Rails和Mysql来做的,我是ROR的新手。
详情如下:
我有不同的类别在产品,如鞋类,服装,配件,袋等,分别为男女。
买方选择产品,将其添加到cart中,然后继续运行。我们只是有一个现金交付类型的支付系统。我们不会创建任何用户帐户。没有用户帐户
如何在Rails中与所有控制器和模型一起实现这一点?
是否应该为每个类别分别设置表?
我应该如何在男女中对所需产品进行分类
以Rails方式提供完整的模式和关系表.
发布于 2013-07-26 06:54:28
您需要Categories表和Products表。在products表中,您需要category_id:integer字段。
Category.rb
has_many :productsProduct.rb
belongs_to :category
has_many :line_itemsCart.rb
has_many :line_itemsLineItem.rb (有product_id:integer和cart_id:integer的表line_items )
belongs_to :cart
belongs_to :product每次有人向product添加cart时,它都会创建一个带有product_id和cart_id的line_item行,如果客户订购了相同类型的更多产品,您也可以添加quantity字段来更新。
对于Men和Women类型的产品,您可以在products表中添加一个字段,该字段将标识该产品是否属于他或她,for_men: boolean, default:true
Product.rb
belongs_to :category
has_many :line_items
scope :men, -> {where(for_men: true)}
scope :women, -> {where(for_men: false)}如果你打电话来
products = Product.all
products.women它将只显示标记为女性类型的产品,其中for_men字段是false。
在按类别提取产品时:
category = Category.find 1
category.products.women 将向您展示products for women of that category。
发布于 2013-07-26 08:45:42
eCommerce存储所需的主要表是。
Product table
Product type - type can define its type and category which it belongs to
Cart - This table depends how you are dealing with cart items.
Users - have an assosisation has many with oder
Orders - have an assosiation with order status
Order status
Discount or Coupon Code
Inquiryhttps://stackoverflow.com/questions/17874502
复制相似问题