This section summarizes the relationships between products, options and option values and then presents how data relating to product attributes is stored in the database.
The 'Product Attributes' sections of CRELoaded and osCommerce are more or less the same and we will begin by looking at them. When setting up a product attribute in the 'Product Attributes' section for any given product, you must do the following: 1) Set up a product option (e.g. Color). 2) Set up option values for that option (e.g. Red, Green, Blue). 3) Attach the option (and any of its option values) to the product and set a price differential for each option value. The relationships between the three elements of Product Attributes are as follows: (Product : Product Option) = (1 : many) (Product Option : Option Value) = (1 : many) CRELoaded Database In order to recreate the above relationships in the database, CRELoaded uses 5 tables. They are: products_attributes products_options products_options_text products_options_values products_options_values_to_products_options We can now see which tables are accessed during each stage of product attribute setup: 1) Set up a product option (e.g. Color). Initial information about product options is stored in two of the tables. First, the product option is given its all-important 'products_options_id' value in the 'products_options' table which the system will use to identify it throughout its life. Secondly, the name of the product option is stored in the 'products_options_text' table. Notice that the 'products_options_id' value in the 'products_options' table and the 'products_options_text_id' value in the 'products_options_text' table must be identical for the 'products_options_id' and the 'products_options_name' to correlate. 2) Set up option values for that option (e.g. Red, Green, Blue). During this phase, an option value is added to a selected product option. First of all, the 'products_options_values_id' is assigned to the option value and is persisted together with the supplied 'products_options_values_name' in the 'products_options_values' table. Notice that the id and name of the option value are stored in one table whereas the id and name of product options are stored in two. The 'products_options_values' table contains no references to product options. The linkage between a product option and an option value is established during this phase by attaching the selected 'products_options_id' to the 'products_options_values_id' in the 'products_options_values_to_products_options' table. At this stage, we have established an option value as being linked to a product option. Of course the user can still choose whether or not the option value will be made available to a customer in the store front, and that selection is part of the final phase. 3) Attach the option (and any of its option values) to the product and set a price differential for each option value. In this final phase, the user does most of the work in selecting a product, then a product option and a related option value before setting a price differential for this particular set of entities. Behind the scenes, only one table - 'products_attributes' - is accessed because it holds all the required fields for identifying each of the related entities(product, product option and option value id's). The table also holds the price prefix and the amount of the price differential itself. When coding for Product Attributes, it is usually useful to be able to get the name if the entity from its id number or vice versa. To do this, use the following tables: Product Options (id <-> name): Use table 'products_options_text', remembering that the 'products_options_text_id' value is also the 'products_options_id' Option Values (id <-> name): Use table 'products_options_values' Last update : 04-08-2008 11:32
|