Stunning Technical Articles

OS Commerce: Read Option and Option Names Directly

Bypass the administrative interface

by Sam Mela

article #00009

In previous articles (OS Commerce: Add Product Options and Values Directly and OS Commerce: Add Product Attributes Directly) I showed how to add product options, option values, and product attributes directly to OS Commerce. In this article, I discuss how to retrieve this information in a useful way.

The information contained in the products_options and products_options_values tables can be used to add product attributes in a general way, by converting from option strings and option value strings to datbase ids.

Here is our strategy:

  1. Create an array, $products_options_rows, indexed by option string and containing option ids.
  2. Create an array, $products_options_values_rows, indexed by option string and containing option value ids.
  3. Select a product.
  4. Build a query consisting of an option id, and option value id, and a product id, and insert it into the database.
  5. Repeat step 4 for each option/option value pair you want to apply to the product.
  6. Repeats steps 3-5 for each product.

Items (1) and (2) are accomplished in Listing 1 below in the functions get_products_options_rows() and function get_products_options_values_rows().