[英]Database for an online store
I'm about to make an online e-commerce site for selling some products like footwear,clothes etc . 我将要建立一个在线电子商务网站,以销售某些产品,例如鞋类,衣服等 。 but I'm unable to figure out how to set up the schema for that (tables and all). 但我无法弄清楚如何为此设置模式(表和全部)。 I'm doing it in Ruby on Rails with Mysql and I'm newbie in ROR. 我正在使用Mysql在Ruby on Rails中进行操作 ,而我在ROR中是新手。
Details are as follows:- 详细信息如下:
I have Different categories in products like Footwear,Clothing,Accessories,Bags,etc separate each for Men and Women . 我在鞋类,服装,配件,包等 产品中有不同的类别 ,分别针对男性和女性 。
The buyer selects the products and add it to cart and proceed to chekout. 买方选择产品并将其添加到购物车,然后进行结帐。 We just have a cash on delivery type Payment system. 我们只有货到付款类型的付款系统。 We wont be creating any user accounts. 我们不会创建任何用户帐户。 No user accounts 没有用户帐号
How should I achieve that in Rails with all the controllers and the models? 我应该如何在所有控制器和模型的Rails中实现这一目标?
Should I make separate table for each of the category ? 我应该为每个类别创建单独的表格吗?
How should I categories the required Products in Men and Women ? 我该如何按男性和女性对所需产品进行分类?
Provide a complete schema and relationships table the Rails way. 用Rails方式提供完整的架构和关系表。
You'll need Categories
table and Products
table. 您将需要“ Categories
表和“ Products
表。 In products table you'll need category_id:integer
field. 在产品表中,您需要category_id:integer
字段。
Category.rb Category.rb
has_many :products
Product.rb Product.rb
belongs_to :category
has_many :line_items
Cart.rb Cart.rb
has_many :line_items
LineItem.rb (table line_items
with product_id:integer
and cart_id:integer
) LineItem.rb (具有product_id:integer
和cart_id:integer
表line_items
)
belongs_to :cart
belongs_to :product
each time someone adds a product
to cart
it will create a line_item
row with product_id
and cart_id
and you can also add quantity field to update if customer order more products of the same type. 每次有人向cart
添加product
时,都会创建一个具有product_id
和cart_id
的line_item
行,如果客户订购了更多相同类型的产品,您还可以添加数量字段以进行更新。
For Men and Women types of products you could add a field in products table that will id id this product is for him or for her, for_men: boolean, default:true
对于男人和女人类型的产品,您可以在产品表中添加一个字段,该字段的ID为该产品适用于他或她的ID, for_men: boolean, default:true
Product.rb Product.rb
belongs_to :category
has_many :line_items
scope :men, -> {where(for_men: true)}
scope :women, -> {where(for_men: false)}
and when if you call 以及何时致电
products = Product.all
products.women
it will show you only products marked as women type, where for_men
field is false
. 它只会显示标记为女性类型的产品,其中for_men
字段为false
。
In case when you extract products by category: 如果您按类别提取产品:
category = Category.find 1
category.products.women
will show you products
for women
of that category
. 将向您products
该category
women
的products
。
The major tables that are required for an eCommerce store are. 电子商务商店所需的主要表格是。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.