user622378
user622378

Reputation: 2346

Shopping Cart ordering tables

I am developing online Shopping Cart system. Now I need to work on adding the items/basket into order tables. I wanted to make sure if I'm going on the right path?

These are the main products tables:

items table

Note: item prices are in the item_options tables

item_options table

item_extras table

Below are the orders tables. As you can see the item name, option name and extras name, prices are copied into orders tables. If any of item name or prices changed - it will not affect the order tables. For example the invoices will not be affected.

orders table

order_items table

order_extras table

Upvotes: 1

Views: 4241

Answers (1)

GordyD
GordyD

Reputation: 5103

I'd like to raise two potential optimisations to this database schema.

Firstly, are there any extras which could apply to two different options e.g. options and extras has a many-to-many relationship? If so you need to add a link table with the following structure:

 optionExtras
 optionId, pk
 extraId, pk

you then alter the extras table by removing the optionId field. This could remove potential redundancy.

Secondly, instead of duplicating item names, option names and extra names why not add a boolean(0-1) row into each table titled active which signifies which entries in each table are currently possible to be selected at the time of ordering. This way the extra redundancy is avoided and products can be re-instated, without any effect on information on old invoices. When you want to change the price or name of a product you just turn the current active record to off and then insert a new record with the new information. The old orders obviously still point the correct id of the entry that is not active.

You could also take this one step further and use the active column to signify products which are available to people that type in special codes e.g. label these products active = 2.

Anyway, those are my thoughts, hope they are helpful!

Upvotes: 1

Related Questions