views:

145

answers:

2

Hi, I new in database design, I want to be sure that i make it well. Please take a look for part of my database design:

My database design for basic shopping cart:

//table that holds shopping cart items that customer choose(not press checkout and order //them)

**shopping_cart**
{
id (int)
product_id (int) fk
product_quantity (int)
customer_user_id (int) fk 
}

//table that holds product order data in time of checkout.(i hold them because supplier //can change after time products attributes value add some attributes or delete and change //the price of product)

**order**
{
id (int)
product_id (int)  fk
customer_user_id (int)  fk
}


//table that connect order  to attribute table for products attributes value in the moment //of   checkout

**order_attributes**
{
id (int)
order_id (int)  fk
attribute_id (int)  fk
}

//main product table
**product**
{
id (int)
sku (int) 
product_name (varchar)
supplier_user_id (int)  fk
}

//connection table many to many 
**product_attributes**
{
id (int) 
product_id (int)  fk
attribute_id (int)  fk
}

//table that holds products attributes (price, weight, color + new attributes that user //will create)

**attribute**
{
id (int)
product_id (int)  fk
attribute_name (varchar)
attribute_value(varchar)
}

Thanks you

+1  A: 

For my money, it is a poor design becasue it uses attribute tables whe are EAV tables and which can cause performance problems. Take the time to actually define the attributes you want to have for the products, there really are mostly simliar for most products (color, size, units(package of 10, single item, etc.). EAV is the last resort.

Store the details of the prices, etc, in the orderdetail table. You do not want the price to change if the product price changes later on down the road.

My structure would be somthing like: Order orderid, date, customerid Order details order_id,Compnay_id,Product_id, part_number,product_name, quantity, price, Unit, Color, size, other attributes Order notes order_id, note

Products product_id,Part_number, product_name, Company_id, product price, color, size, Unit

Better to have null columns (unless you have hundreds of attributes which you won't generally) when some products don't have the same attrubutes) Further if you want complete specs for a product, consider puttingthem in a large varchar filed and putting a full text index on it. This should perform way better than an EAV table.

HLGEM
Thank you very much!
Yosef
Why is magento use EAV tables? also in my application I dont know the attributes of product because supplier define them.Soo if will every supplier will have ability to add new attribute the table products will have a lot of columns.
Yosef
EAV tables are performance killers and hard to write code against. If you don't know how many attriubtes a part has, you don't even know how many times to join to the table. Since every query joins mulitple time to this one table, it creates locking issues and in general means that once you have a real workload, performance will be horrible. I would not let suppliers add columns either. There are a half dozen or so attributes (color, dimensions, weight, units, etc.) that are needed to choose a part. The others are descriptive and should be stored in one large field with a full text index.
HLGEM
I've worked with application that had parts from thousands of vendors which were highly technical in their description and we never needed more than that.
HLGEM
People make too much of the ability to be flexible, flexibility in databases comes at a huge performance cost and is unnecessary most of the time if you do your due diligence and figure out what is really needed. WE have a COTS prduct that we paid over 100,000 dollars for that was designed this way that is terribly slow and doen;t have all the stuff it should have so we have spent countless man-hours adding fields to it that should have been there. It has gotten so bad that we are getting ready to scrap it for something that works without extensive customization.
HLGEM
Thank you very much.What do you think about spree(ecommerce - rubi on reils) database design?see models diagramhttp://spreecommerce.ru/attachments/download/17/models.svg
Yosef
+1  A: 

Hmm there are two tables that you can remove from your design: order_attributes, product_attributes. Otherwise, your select query would be very slow having to join from so many tables. You can store the attributes as columns in the order and product table.

ovais.tariq
Thank you very much!
Yosef
if you liked my answer you can set it as the correct one too lol
ovais.tariq