lucassimines's avatar

Ecommerce Orders table

Hello guys,

I'm developing a simple E-Commerce and I need help about the orders table.. When an order is made in my Store, I need to copy some important products info like (Title, Price, Sku) and some customer info like (Name, Shipping Address) in order to keep a history of it. Now, the best way to do that is creating an "order_info" table that stores all of those information? Thanks in advance.

0 likes
6 replies
ctroms's avatar

One option could be to create an orders table and an order_items table. You can store item specific data such as title, sku, and price for each item in the order items table as well as a foreign key to the order. The orders table can contain the billing and shipping address, order number, total amount, etc and a foreign key to the customer.

1 like
tykus's avatar

Similar to @ctroms suggestion, but I use the same line_items table for the shopping cart and order products, swapping out the cart_id property (to null) and adding the order_id whenever the order is successfully placed. Also, I keep the product name and price in the line_items table to maintain order histories.

1 like
lucassimines's avatar

@ctroms @tykus_ikus thanks for the help! I created an order_items table and it worked, now I have to create the Cart model. @tykus_ikus it seems interesting using the same table for shopping cart and order products, maybe I'll do this.

frezno's avatar

i store evreything (cart items, uswe credetials etc) in the session. If user checks out anonymiously the session will be killed after checking out.

If user wants to register or is logged in, the cart is stored to a database in two different tables, an order table and an order items table.

1 like
ctroms's avatar

@lucassimines No problem. In addition to the other suggestions, you can also consider a separate table for your cart. This could be useful if you want to allow your users to place an order for some of the items in their cart and save the rest for a later order. If you go this route, rather than creating a carts and cart_items table consider storing your cart_items in a json column or a text column with your data json encoded or serialized.

1 like
Filip_Zdravkovic's avatar

@lucassimines Like @frezno, I store a cart in session. On the other hand, I have orders table and there is a One-To-Many relationships between User and Order models. Finally, if the charge succeeded, then save those cart items in orders table.

1 like

Please or to participate in this conversation.