我即将建立一个在线电子商务网站,用于销售鞋类,服装等产品。但我无法弄清楚如何设置架构(表和所有)。我在 Ruby on Rails 中使用 Mysql 进行此操作,而且我是ROR中的新手。
详情如下: -
我在产品中有不同的类别,例如鞋类,服装,配饰,手袋等分别为男士和女士< /强>
买方选择产品并将其添加到购物车并继续chekout。我们只有一个货到付款类型付款系统。我们不会创建任何用户帐户。没有用户帐户
我应该如何在Rails中实现所有控制器和模型?
我应该为每个类别制作单独的表格吗?
我应该如何在男性和女性中对所需产品进行分类?
提供完整的架构和关系表 Rails方式。
答案 0 :(得分:3)
您需要Categories
表和Products
表。在产品表格中,您需要category_id:integer
字段。
<强> Category.rb 强>
has_many :products
<强> Product.rb 强>
belongs_to :category
has_many :line_items
<强> Cart.rb 强>
has_many :line_items
LineItem.rb (表line_items
与product_id:integer
和cart_id:integer
)
belongs_to :cart
belongs_to :product
每当有人向product
添加cart
时,它会创建line_item
行product_id
和cart_id
,您还可以添加数量字段进行更新如果客户订购更多相同类型的产品。
对于男性和女性类型的产品,您可以在产品表格中添加一个字段,该字段将标识此产品适合他或她,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
women
category
显示{{1}}。
答案 1 :(得分:1)
电子商务商店所需的主要表格是。
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
Inquiry