Zencart Related Products

Zen-Cart
Zen-Cart
Zen-cart is an excellent open source ecommerce shopping cart system. One of the features I like about Zen-cart is that once you understand the templating structure, writing plugins becomes pretty easy.

One of the features I enjoyed using with osCommerce, was a plugin for creating a related products box below a displayed. The plugin was easily implemented, and used an extra field add to the database. That was a great asset, that I felt missed using. Zen-cart offers something very similar in its port of XSell (Cross Sell). This feature would work fine if you are adding a few products at time, and do not have many related products. However, in my case, I have about 4,000 items in my catalog. The products are mostly lighting fixtures, which for must companies have coordinating fixtures for each room. This would be a bit cumbersome to create all of the related items. This is why I decided to write a quick plugin to get this simple functionality back.The code works by simply selecting products that have the same products_family value from the products table. You will first need to add this field to your database.

The default products table is “zen_products”, and in your favorite MySQL editor add:

ALTER TABLE zen_products ADD COLUMN products_family VARCHAR(50);

Next, you will need to add values to your new field family_products. The easiest to do this is to use custom fields in Easy Populate. I added the code to Easy Poplulate for zen-cart to be able to add your own custom fields to the import/export file.

Now that you’ve got the fields added to the database, it’s time to upload some files. Download Zencart Related Plugins. Read the included readme file, and upload to your zen cart folder.

Open the file /includes/templates/CUSTOM/templates/tpl_product_info_display.php and find the block around line 463:

<!--bof also purchased products module -->
	<?php require($template->get_template_dir('tpl_modules_also_purchased_products.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_also_purchased_products.php');?>
<!--eof also purchased products module -->

Above that copy this into your file:

<!--bof also related products module-->
	<?php require($template->get_template_dir('tpl_modules_related_products.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_related_products.php');?>
<!--eof also related products module-->

You should now see products being displayed under the products description. You will want to add some CSS styles to the box to your liking. Default styles should be:

#relatedProducts	{text-align: center;}
.centerBoxContentsRelatedProduct	{float: left; margin: 1em 0;}