The Commerce Product module, part of the Commerce package, creates two tables, the commerce_product table and the commerce_product_revision table. There is a matching Commece Product UI module providing forms for creating products.

Product type

You create a product type first then create products of that type. product type is similar to a content type and lets you give a set of products a specific characteristic.

Product ID

The Product ID is the internal unique primary key and is integer. Product numbers are rarely integers. Use the SKU field for your product identifier and leave the product ID field for internal use within Commerce.

SKU

The SKU, the Stock Keeping Unit, is the visible product identifier and has to be unique within the table. The SKU is a long string to accommodate any type of identifier. The one product may be in stock in different packages, single, six pack, retail, OEM, etc. You can put all those complications into the SKU string.

Prerequisites

The Commerce Product module requires the Commerce module and the Commerce Price module. Both of those modules have several requirements.

Inserting products from your code

You may want to insert existing products from external systems, something common to wholesalers and retailers importing from suppliers.

  1. Switch on the Product UI module and create a product type.
  2. Assume the type is 'example'. Create a product object of that type using:$product = commerce_product_new('example');
  3. Add your data to the product:$product->sku = 'abc-127';
  4. Save your data into the product table:commerce_product_save($product);

The save creates a revision. After you create the product object, dump the product object to see the attributes. View the commerce_product and commerce_product_revision tables to see the columns.

You can also add a price when you add the product. See the commerce_price table for details.

You can also create some products using the Product UI module then view the entries created in the tables.

commerce_product_save() will not save the product if you put anything in the product_id attribute. Your existing product id has to go in the SKU field which is a problem if your existing system has both a product id and an SKU.

There is a data field in the product table for extra information from the original system.