db中的购物车 - 订单行表或单独的购物车表?(Shopping cart in db - order lines table or separate cart table?)




I want to store the cart data of my multitenant app in the database.

I am wondering if it would be better to have a separate table (a project I work on does it that way but I think they migrated from sessions to that solution) or if I should put everything in the order lines table and have an order status to decide if its part of a cart or an order.

What would be the pros and cons for each solution?



但是,与下订单和购物车产品相关的属性通常不同。 购物车相关数据基本上保持用户恢复其活动的状态,并且可能呈现可能被消费的产品(有点不寻常)。 另一方面,与订单行相关的数据很重要,它们与交易,财务信息,股票,历史,趋势等相关联,这是实际重要的数据。

因此,下订单是具有价值的数据,可以进行分析和处理,而购物车只是为了方便用户而存储。 通常,最好将它们分开以保持灵活性和可扩展性

If, within your system, the data related to the cart are exactly the same as the order line and only differ by a status, then you could keep all in the same table and differentiate by the value of the foreign key to a status table.

However the properties related to placed orders and products of a cart usually differ. The cart related data basically hold a state for a user to resume her activities and possibly present products that are likely to be consumed (a bit unusual). On the other hand data related to order lines are important, they are connected with transactions, financial info, stock, history,trends etc, this is the data that actually matters.

So the placed orders are the data with value, that get analysed and processed, while the cart is only stored for user's convenience. Generally it is best to keep them separated for flexibility and scalability.