Stunning Technical Articles

OS Commerce: Add Product Attributes Directly

Bypass the administrative interface

by Sam Mela

article #00008

In a previous article (OS Commerce: Add Product Options and Values Directly) I showed how to add product options and option values directly to OS Commerce. In this article, I show how to add product attributes.

But what is the difference between options, options values, and attributes?

Table 1 below explains the difference in these terms.

Option: An option is something like "size", "color", "flavor".
Option Value: An option value is one possible value that an option can have. For instance, option values for "size" could be "small", "medium", or "large". Or option values for "flavor" could be "vanilla", "chocolate", or "strawberry".
Product Attribute :

Product attributes are option/option value pairs that get applied to a product.

For example, a shirt product might have size/small, size/medium, and size/large product attributes applied to it.
Table 1: Definitions

Figure 1 below shows how the products_attributes table works. It points to id fields in products, products_options, and products_options_values table, thus relating them.


Figure 1: Relationship of OS Commerce Database Tables

Let's look at how we might add entries to the products attributes table, to define options and option values for some products.

We're going to add attruibutes to three products, a shirt, a candy bar, and something else, as shown below:

Product ID Product Model Product Name
28 x100 shirt
29 x101 candy bar
28 x102 something else

A SQL statement in Listing 1 shows how to add attributes for these products.

SQL Statement to insert option names into the data base

INSERT INTO `products_attributes` (`products_attributes_id`, `products_id`, `options_id`, `options_values_id`, `options_values_price`, `price_prefix`) VALUES
(1, 28, 1, 1, 0.0000, '+'),
(2, 28, 1, 2, 0.0000, '+'),
(3, 29, 3, 11, 0.0000, '+'),
(4, 29, 3, 10, 0.0000, '+'),
(5, 29, 3, 12, 0.0000, '+'),
(6, 30, 2, 3, 0.0000, '+'),
(7, 30, 2, 9, 0.0000, '+');
Listing 1

Upon running the above query, the OS Commerce Administration "Products Attributes" page should show something like Figure 2.


Figure 2