If you have ever tried to add a page to Zen Cart it is a total pain in the ass. To give my clients’ Zen Cart sites a boost in SEO and usability I have been moving their non-catalog information over to WordPress. I have been hosting WordPress in a sub folder of the shopping cart, e.g., http://mycart/blog/.
Keeping the navigation in sync takes a little effort. To cut down on that effort I created a quick WordPress plugin that queries Zen Cart’s database tables and displays your Zen Cart categories in the WordPress sidebar.
/*
Plugin Name: Products
Plugin URI: http://www.levisenft.com/
Description: Zen Cart Categories
Author: Levi Senft
Version: 1
Author URI: http://www.levisenft.com/
*/
define(‘TABLE_CATEGORIES’, ‘zen_categories’);
define(‘TABLE_CATEGORIES_DESCRIPTION’, ‘zen_categories_description’);
define(‘DIR_WS_CATALOG’, ‘/~lsenft/zencart/’);
define(‘HTTP_SERVER’, ‘http://localhost’);
function zen_cat() {
echo ‘<li class="widget widget_zen_cat"><h2 class="widgettitle">Products</h2><ul>’;
$categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = 0
and c.categories_id = cd.categories_id
and c.categories_status= 1
order by sort_order, cd.categories_name";
$results = mysql_query($categories_query);
$item_count = 1;
while($row = mysql_fetch_assoc($results)) {
echo ‘<li class="zen_cat_item zen-cat-item-’ . $item_count . ‘"><a href="’ . HTTP_SERVER . DIR_WS_CATALOG . ‘index.php?main_page=index&cPath=’ . $row['categories_id'] . ‘">’ . $row['categories_name'] . ‘</a>’;
$subcats_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = " . $row['categories_id'] . "
and c.categories_id = cd.categories_id
and c.categories_status= 1
order by sort_order, cd.categories_name";
$subcats_results = mysql_query($subcats_query);
if (mysql_num_rows($subcats_results) > 0) {
$subitem_count = 1;
echo ‘<ul>’;
while($subcats_row = mysql_fetch_assoc($subcats_results)) {
echo ‘<li class="zen_cat_item zen-cat-item-’ . $subitem_count . ‘"><a href="’ . HTTP_SERVER . DIR_WS_CATALOG . ‘index.php?main_page=index&cPath=’ . $row['categories_id'] . ‘_’ . $subcats_row['categories_id'] . ‘">’ . $subcats_row['categories_name'] . ‘</a>’;
$subitem_count++;
}
echo ‘</ul>’;
}
echo ‘</li>’;
$item_count++;
}
echo ‘</ul></li>’;
}
function init_zen_cat(){
register_sidebar_widget("Products", "zen_cat");
}
add_action("plugins_loaded", "init_zen_cat");
?>