Adding a new Product Type in Zen Cart

Have you ever wanted to go down the rod of creating a new product type in Zen Cart, but, found the documentation lacking? We present a howto, but only for those already skilled in Zen Cart programming.

Adding a new product type in Zen Cart is a great way to insulate yourself from Zen Cart updates, without having to worry about all the code you changed. Go ahead and add all the fields you want, change product screens, etc.

Adding a new product type is not a trivial task. You do need skills!
There are a number of potential reasons for wanting to add a new product type. You might want to store a new type of product entirely. Or, you might want to add a bunch of new data to the standard general product. Why would you add a new product type merely to add data to the standard product type, instead of simply adding more fields and changing programs accordingly? A new product type insulates you for the most part from Zen Cart updates. The new product type runs from separate code, so, changes in Zen Cart normally do not require any changes in your product type code. So, you can make changes to the product info screen, accept a bunch of new fields in the admin, and, not changes when Zen Cart updates. This in turn makes Zen Cart updates easier to do.

We will not go into detail as to how each step is done, the reader should be familiar with using MySQL, uploading or copying files, programming in php, etc. Adding a new product type is not likely to be possible otherwise, without getting someone to do it for you. This guide was written with Zen Cart 1.3.9h in mind.

Steps to adding a new product type in Zen Cart:

  • Add an entry to the PRODUCT_TYPES table. The most important field here is type_handler. This field is used to build the URL so that the handler for your product type is accessed. Hereafter, we will refer to the type_handler value you set as simply {type_handler}, so, in later parts of this document, replace {type_handler} with whatever value you put into it.
  • Add entries to the PRODUCT_TYPE_LAYOUT table. This table is used to set options for the product type, all options need to have code written to actually use them. If you use the standard general product type as a base, then, that’s a good starting point for what options you want here.
  • Optionally, add entries to the GET_TERMS_TO_FILTER table. This is used in sideboxes to allow filtering of product lists, of course it also has to be coded. An example is the manufacturer sidebox.

The admin files in /admin/includes/modules are shared amongst all product types. You only need your copy in your type_handler directory if you need to change the behavior of the file, except for the files marked as Required. Not all possible admin/includes/modules files are listed here, only the most common ones changed.

The most common admin files used include:


/admin/{type_handler}.php
  • Used to point to the other functions for products, and, display the product list.
  • You can often simply copy product.php and rename it and use as is
  • If using modify functions like copy_to_confirm, in Zen 1.3.9h, this seems to require setting $product_type due to a bug in the code
  • You MUST create this file.

/admin/includes/languages/english/{type_handler}.php
  • You can start with products.php if you have not changed much
  • Put any new defines for add/edit screens here for new fields, etc.
  • Generally, this file is required

/admin/includes/extra_datafiles/somename.php
  • This file would contain your new table (or other) definitions, if any, optional

/admin/includes/modules/{type_handler}/collect_info.php Required
  • Used to gather data and display in add/edit products screens
  • You need to put new fields here, and new TABLES you might need to get data from

/admin/includes/modules/{type_handler}/collect_info_metatags.php Required
  • Normally not changed, just copy the general products version

/admin/includes/modules/{type_handler}/preview_info.php Required
  • Used to preview content before updating and adding
  • Normally, this does not need to be changed unless you want to show new info

/admin/includes/modules/{type_handler}/preview_info_meta_tags.php Required
  • Normally not changed, just copy the general products version

/admin/includes/modules/{type_handler}/update_product.php
  • Used to save the data to the database after preview
  • Only needed if you added fields or tables

/admin/includes/modules/{type_handler}/update_product_meta_tags.php
  • Used to save the data to the database after preview, not normally needed.

/admin/includes/modules/{type_handler}/copy_to_confirm.php
  • Used to copy a product, generally needed if you added more tables for product info

/admin/includes/modules/{type_handler}/delete_product_confirm.php
  • Used to delete a product, generally needed if you added more tables for product info

/admin/includes/modules/{type_handler}/move_product_confirm.php
  • Used to move a product, rarely needs changes

The most common non admin files used include:


/includes/extra_datafiles/{type_handler}.php
  • This file would contain your new table (or other) definitions, if any, optional

/includes/languages/english/{type_handler}_info.php Required
  • Make a copy of product_info.php to start with, add any new fields or changes

/includes/modules/pages/{type_handler}_info/header_php.php Required
  • Typically, just copy from the product_info directory, no need to change

/includes/modules/pages/{type_handler}_info/jscript_main.php Required
  • Typically, just copy from the product_info directory, no need to change

/includes/modules/pages/{type_handler}_info/jscript_textarea_counter.js Required
  • Typically, just copy from the product_info directory, no need to change

/includes/modules/pages/{type_handler}_info/main_template_vars.php Required
  • Defines the standard zen cart product data to be used, typically, small changes unless you modified the product table
  • Be sure and update the template names to reflect the product type at a minimum
  • Also change the notifier names, and, any product type layout variables
  • Add any new type)handler switches and logic

/includes/modules/pages/{type_handler}_info/main_template_vars_product_type.php Required
  • Defines the new product data used for this product type, if, you defined new tables
  • Change the notifier names, and, add the logic to get the new data, and, store in variables to be used by the templated

/includes/templates/YOURTEMPLATE/templates/tpl_{type_Handler}_info_display.php
  • Name needs to match that set in main_template_vars.php

/includes/templates/YOURTEMPLATE/templates/tpl_{type_Handler}_noproducts.php
  • Typically, not needed. If you need a different no product page, then, be sure this name matches that set in main_template_vars.php

blog comments powered by Disqus

© 2017 by 5 Diamond IT Consulting, Contact Us
Privacy Policy | Site Map

Open source software we work with includes Apache HTTP server, cURL, Fedex Shipping for osCommerce and Zen Cart, MySQL, Mariadb, osCommerce shopping cart, PHP, and Zen Cart shopping cart. We offer services such as shell scripting, HP3000 consulting. Tools we recommend for small business include KALL8 toll free phone service, VOIPo VOIP phone service