Zen Cart Logo
Forums / Code Collaboration / Attributes and their place in the DB

Attributes and their place in the DB

Views: 3,373

Results 1 to 5 of 5
4 Sep 2014, 7:52 PM
#1
g2ktcf avatar

g2ktcf

Totally Zenned

Join Date:
Feb 2011
Location:
Lumberton, TX
Posts:
636
Plugin Contributions:
0

Attributes and their place in the DB

I have been examining the database tables in order to understand completely how products in an order are related to their attributes.

A bit o prep for the question...if an order were to contain the following [model] - [Option1][Option1 Value] [Option2][Option2 Value] with three different combinations...

Product 1 - Color: Red Size: Medium
Product 1 - Color:Blue Size: Medium
Product 1 - Color: Green Size: Medium

Will there be three individual db entries for the same model number in the orders_products table? I do not see where anything says "yes" but it is the only way I can see how the orders_products_attributes table can get a link back to a specific line item in the order.

4 Sep 2014, 7:59 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Attributes and their place in the DB

g2ktcf:

I have been examining the database tables in order to understand completely how products in an order are related to their attributes.

A bit o prep for the question...if an order were to contain the following [model] - [Option1][Option1 Value] [Option2][Option2 Value] with three different combinations...

Product 1 - Color: Red Size: Medium
Product 1 - Color:Blue Size: Medium
Product 1 - Color: Green Size: Medium

Will there be three individual db entries for the same model number in the orders_products table? I do not see where anything says "yes" but it is the only way I can see how the orders_products_attributes table can get a link back to a specific line item in the order.
You'd wind up with 3 separate records in the orders_products table (one for each combination) and then 6 records total (2 attributes * 3 combinations) in the orders_products_attributes table; each of the records will contain the same orders_id value, pointing back to the overall order.

4 Sep 2014, 8:09 PM
#3
g2ktcf avatar

g2ktcf

Totally Zenned

Join Date:
Feb 2011
Location:
Lumberton, TX
Posts:
636
Plugin Contributions:
0

Re: Attributes and their place in the DB

lat9:

You'd wind up with 3 separate records in the orders_products table (one for each combination) and then 6 records total (2 attributes * 3 combinations) in the orders_products_attributes table; each of the records will contain the same orders_id value, pointing back to the overall order.

Perfect! Exactly what I thought it would have to be. THANKS!

4 Sep 2014, 8:23 PM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: Attributes and their place in the DB

The only time the orders_products table will have multiple, duplicate products_model entries is if the customer orders two of the model. Since each could still have separate attributes, they are tied together in the orders_products_attributes table.
The order_id is tied to the orders_products_id and then to the orders_products_attributes_id
The duplicate products_model entries are given separate orders_products_id. The separate orders_products_id entries then get the tied to the appropriate orders_products_attributes_id.

Beat me to it.:P

4 Sep 2014, 8:25 PM
#5
g2ktcf avatar

g2ktcf

Totally Zenned

Join Date:
Feb 2011
Location:
Lumberton, TX
Posts:
636
Plugin Contributions:
0

Re: Attributes and their place in the DB

dbltoe:

The only time the orders_products table will have multiple, duplicate products_model entries is if the customer orders two of the model. Since each could still have separate attributes, they are tied together in the orders_products_attributes table.
The order_id is tied to the orders_products_id and then to the orders_products_attributes_id
The duplicate products_model entries are given separate orders_products_id. The separate orders_products_id entries then get the tied to the appropriate orders_products_attributes_id.

Beat me to it.:P

I appreciate it all the same! :smile: