• After days of intensive searching I have only found one website offering a solution to displaying Zencart items inside a WordPress page.

    I don’t want to use the WordPress on Zencart plugin. I want an existing WordPress website, which is used as a CMS, to display some or all of the products available in the Zen Cart shop.

    I found a possible solution here, I can’t get it working but I think it is possibly a simple problem to do with the ‘DEFINE’.

    I’m hoping someone here can explain the links needed in the DEFINEs- I & 2 others get the same error message “Parse error: syntax error, unexpected ‘:’ in /home/noah/public_html/blog/wp-content/plugins/zencat/zencat.php on line 13”

    Line 13 is the either the third or 4th DEFINE

    “define(‘DIR_WS_CATALOG’, ‘/~lsenft/zencart/’);
    define(‘HTTP_SERVER’, ‘http://localhost’);”

    My WordPress installation is in public_html and Zencart is in public_html/shop – what should I put in the defines?

    Below is the entire code which when saved in the plugins folder as a php file creates a plugin called Products

    <?php
    /*
    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");
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Looks like you’re using the code from http://www.forgeniuses.com/2009/11/19/wordpress-plugin-sidebar-widget-for-displaying-zen-cart-categories/

    I tried this code as well, but I think the problem is that he has his ZenCart installation on the root of the server and his wordpress blog at a subdirectory, which I think is the opposite of what you’re going for.

    It appears that plugin is querying the WP database, and not the ZenCart one (I could be completely wrong about that though).

    I’m currently looking for a similar solution to display ZenCart products on a WP homepage (WordPress installed on root, ZenCart on subfolder). If you find anything, please let me know.. I will do the same 🙂

    Thread Starter Stingraynut

    (@stingraynut)

    HI SDD, yes thats right, I posted there and have received the reply below, though I haven’t had time to check it yet – please let me know if you get this working and I will do the same here.

    Levi Senft says:
    December 3, 2010 at 10:50 pm

    Rob,

    DIR_WS_CATALOG should be the folder of your ZenCart install (relative to your webroot). HTTP_SERVER should be your domain name. Based on the default values my ZenCart would be hosted at: http://localhost/~lsenft/zencart/

    If your ZenCart isn’t in a folder DIR_WS_CATALOG can be left blank.

    If this were a proper plugin these would be settings accessible through the admin, but really this is just a quick hack.

    Hey Stingraynut,

    Yup.. its the database.

    When WordPress is installed at the root, the WP database is where the mysql_query is going to query, not the ZenCart DB. So, even if you did fix the parse error, you’ll end up getting an awesome “Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in […]/wp-content/plugins/zen-cart.php on line 49” error.

    These definitions:

    define(‘DIR_WS_CATALOG’, ‘/~lsenft/zencart/’);
    define(‘HTTP_SERVER’, ‘http://localhost’);

    are really only used for the code:

    echo ‘<li class=”zen_cat_item zen-cat-item-’ . $subitem_count . ‘”>’ . $subcats_row[‘categories_name’] . ‘’;

    Basically, that is for the “while” statement that outputs the proper link URL in the sidebar. So, it should be set based on your configuration:

    define(‘DIR_WS_CATALOG’, ‘/YOUR-ZENCART-FOLDER/’);
    define(‘HTTP_SERVER’, ‘http://YOURWEBSITE.COM’);

    (as for the “parse error”, I didn’t get one.. maybe check to see if its a semicolon and not a colon on line 13?)

    The real meat lies here:

    define(‘TABLE_CATEGORIES’, ‘categories’);
    define(‘TABLE_CATEGORIES_DESCRIPTION’, ‘categories_description’);

    These are the actual tables in the ZenCart database. I changed the name from ‘zen_categories’ to ‘categories’ because that’s how the tables are laid out in my particular installation, can’t be sure about yours, you’ll have to look in your ZenCart DB.

    Sooo… I added a mysql_connect function to call the ZenCart DB, and it works.. not perfectly, mind you, but enough for me to build off this code (I’ll keep you in the loop on that 🙂 ).

    mysql_connect($hostname,$username, $password) OR DIE (‘Unable to connect to database! Please try again later.’);
    mysql_select_db($dbname);

    *$hostname is your database host URL (depending on your server configuration, localhost may work)
    *$username is the DB username
    *$password is the password

    Unfortunately, this is NOT secure in the slightest, as you’re dropping your ZenCart DB login info into a flat file (scary!), but it does query the right DB and it did put a list of my products in the sidebar from the widget (yay!).

    What I might do is build an admin for this plugin that lets you enter the ZenCart DB info into the WordPress DB and then call it from there, but that’ll take me a bit of time (I’m not the world’s greatest php developer 🙂 ).

    I’m using a ZenCart theme that pulls WordPress functions (headers, footers, CSS) directly into ZenCart which I found the (genius) code for here:

    http://michaelwender.com/2010/10/28/integrating-wordpress-and-zencart/

    Not sure if that’s what you’re attempting to do also, but I gotta plug that code!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘show zencart categories/products in WordPress main or sidebar’ is closed to new replies.