While there are several product types already implemented by core and contributed E-Commerce modules, there will always be new needs not already covered off. One of the easiest ways to use the E-Commerce API is to write a module implementing a new product type.

At a minimum, a product type module has four functions:

hook_help() Provides a module description and contextual description of the product type.
hook_perm() Defines permissions for the product type--typically, 'create' and 'edit own'.
hook_access() Determines the access permissions of a particular user.
hook_productapi() Uses the product API to define characteristics and behaviours of the product type.

If you want to store information on your product beyond that stored in existing tables, you'll need to include a .install file to create the appropriate table and fields.

To get started, you'll probably want simply to choose one of the existing product type modules and modify it to fit. For a useful model, see the core E-Commerce tangible.module, which defines the 'shippable product' product type.

If you're unfamiliar with Drupal methods for writing node modules, start by studying the example module documentation. There you'll find details on how to implement load, insert, update, delete, and other core methods for working with node types. If you are adding fields in your product type module (e.g,. a "manufacturer" field), you will use use the same general approach, except that instead of implementing each operation in a separate function, e.g., example_load(), you'll do it all as options within your module's _productapi() function.

Quick tips:

  • Create a new directory for your module and copy tangible.module and tangible.install there. Rename them to your product type, e.g., 'potato.module'.
  • Choose a machine-readable and a human-readable name for your product type. Ideally they'd be similar. :) The machine readable name is equivalent to 'tangible', while the human readable one is eqivalent to 'shippable product'.
  • Replace all occurrences of 'tangible' with your machine-readable name (the name of your module), and all occurrances of 'shippable product' and 'shippable products' with the equivalents for your product.
  • If you need to store extra information about your products, design a table and adjust the insert, update, delete, load, and fields productapi options to reference your table's fields. Adjust the .install file to create your table.
  • Look over the rest of the .module file and fix up references. E.g., provide appropriate help text in the hook_help() function describing your product.
  • Delete the last two functions; you won't need them.

See the tips, tricks, and code snippets pages for additional ideas, e.g., how to make your module inherit the tangible functionality.