An Introduction to Product Types in Zen Cart v1.2 1. Introduction A much requested feature in Zen Cart was the ability to have unique information layouts for different types of products. For example a Music Video needs to have different information stored and displayed, compared to say a Garden Bench. Previously there has been no easy way for a Zen Cart Store user to do this without ripping apart the core code. The Product Type system was designed to help alleviate that problem. Throughout this mini-tutorial we will use the Music Product type that comes as standard with V1.2 as an example. It is not in anyway meant to be an exhaustive treatise on implementing your own product type, as this will always depend on exactly what you are trying to implement. However it should provide enough of an overview to get you started. As ever our support forums at www.zen-cart.com, are always there to help you when you get stuck. 2. Database Schema The Product Types System(PTS) uses a number of required, and some @@TODO non-required tables within the Zen Cart database. The required database tables are PRODUCT_TYPES PRODUCT_TYPE_LAYOUT GET_TERMS_TO_FILTER _PRODUCT_TYPES The _PRODUCT_TYPES database is used to track base information relating to the product types currently installed. It consists of 8 fields. type_id type_name type_handler type_master_type allow_add_to_cart default_image date_added last_modified type_id is an auto_incrementing field and is used to cross reference the type with other Database Tables used by the PTS. type_name is user defined, but you should try and stick with the naming conventions that the core team have decided on. For example in ZC 1.2 we have Products - General for the standard product, and Product - Music for a product type designed for Music CD's. Then we have Document - General for a basic layout for an information only Document, and Document-Product for a Document that can be sold. These names are used in the drop down that appears in the admin product creation pages. type_handler again is user defined and is used to build the URL to the code that actually does the work for the product type. It is best to define this similarly to the type_name. For example if the type_name is Product-Music, the type_handler would be product_music. For compatibility across operating systems you should always stick to lower case for the type_handler. More explanation will be given later as to how the type_handler is used to access the unique code for a given product type. type_master_type is used to link product types together. This is mainly used if you want to build separate sideboxes to display a category tree of just certain product types. For example the Document types are linked so that we can provide a sidebox that can be used just to navigate categories containing Document Types. allow_add_to_cart. Provision is made with this field to create product_types that are for information purpose only, and because of that you do not want to allow the shopper to add them to the cart. The basic Document type is a good example of this. default_image is reserved for future usage. date_added/last_modified are for internal code use only. _PRODUCT_TYPE_LAYOUT It has always been possible in Zen Cart using the admin interface to decide which elements of a product's information are displayed. Originally this information was saved in the CONFIGURATION table. However as different product types will have differing types of information, we now use a separate table for product types. The layout of this table is similar to an entry in the configuration table. The fields are configuration_id configuration_title configuration_key configuration_value configuration_description product_type_id sort_order last_modified date_added use_function set_function an example here is an entry for the music product type. INSERT INTO product_type_layout (configuration_title, configuration_key, configuration_value, configuration_description, product_type_id, sort_order, set_function, date_added) VALUES ('Show Record Company', 'SHOW_PRODUCT_MUSIC_INFO_RECORD_COMPANY', '1', 'Display Record Company on Product Info 0= off 1= on', '2', '4', 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'), array(\'id\'=>\'0\', \'text\'=>\'False\')), ', now()); This lets the store admin decide whether the Record Company linked to the music product is shown on the product info page. Of course you would need to code the music product info page to use this value e.g. if (SHOW_PRODUCT_MUSIC_INFO_RECORD_COMPANY == '1') { ?>