WordPress.org

Support

Support » Plugins and Hacks » Display Zen Cart Sidebox inside Widget

Display Zen Cart Sidebox inside Widget

  • DivaVocals

    @divavocals

    I need help trying to get Zen Cart sideboxes to display within a WordPress widget. Though I think I am on the right path, I have officially hit a wall and was hoping that someone might be able to point me in the right direction on how to get unstuck..

    I am using a Zen Cart add-on called Sideboxes Anywhere..

    Following these instructions I was successfully able to display the new products sidebox by adding the following code to my template.

    <?php
      $zcSBmodule = 'whats_new.php';
      $zcSBlayout = 'left';
      require ("/path/to/zencart/single_sidebox.php");
    ?>

    This is great except I would like to display the sidebox inside a widget, and I have been unsuccessful thus far.

    I have tried using the Executable PHP widget with no luck. When I add the code above, all the widgets in the sidebar disappear along with the footer.

    I also tried creating my own custom widget with the following code:

    <?php
    /*
    Plugin Name: Zen Cart Whats New Sidebox
    Plugin URI: http://www.yoursite.com/
    Description: Display Zen Cart Whats New sidebox inside a WordPress widget. Requires the Zen Cart Sideboxes Anywhere add-on to work.
    Author: Me
    Version: 1.0
    Author URI: http://www.yoursite.com/
    */
    
    function zen_cat() {
      $zcSBmodule = 'whats_new.php';
      $zcSBlayout = 'left';
      require ("/path/to/zencart/single_sidebox.php");
    }
    function init_zen_cat(){
        register_sidebar_widget("ZC Whats New Sidebox", "zen_cat");
    }
    add_action("plugins_loaded", "init_zen_cat");
    ?>

    This too results in the all the widgets in the sidebar & the footer disappearing.

    I am hoping that the solution is something simple that I am overlooking.. Would sure appreciate some input on this from any kind soul who can help..

Viewing 15 replies - 1 through 15 (of 53 total)
  • TraciBunkers

    @tracibunkers

    Did you get this figured out? I would like to do the same thing. OR, if there is a way to display random products, not just the new ones.

    TraciBunkers

    @tracibunkers

    I can’t even get it to display by adding the code to my sidebar.php template. I’ve tried adding it every place imaginable, but can’t get it to work.

    DivaVocals

    @divavocals

    No I didn’t get it figured out which is why I posted this.. Have not gotten any responses..

    TraciBunkers

    @tracibunkers

    Too bad. I was hoping perhaps after you posted here, you figured it out. I posted on the zen cart forum to try to get help getting it to work in my sidebar.php file, but got no replies.

    I got it to work in a widget as an iframe, but the problem of course is if someone clicks on a link, it just opens it up right there in the widget, and doesn’t go to the cart.

    If I had figured it out I would have posted something very different than a request for help.. 🙂 If I had found a solution, I would have shared it..

    It’s frustrating because it seems like it shouldn’t be that hard. Since there are widgets for etsy and flickr, I really wish there was one for zen cart.

    Well I’m sure it’s not hard.. It’s just that no one has shared the answer.. **shrug** I can’t expect that everyone is gonna share the answer for free.. So eventually I may look into paying a developer to create this widget for me.. I’m not opposed to paying for this if needed..

    In the meantime, since I’m using the Catalyst framework to develop my theme, I may have a possible workaround I’m gonna try to see if it works.. (won’t work unless you are using the Catalyst theme framework)

    I wish you luck finding an answer as well..

    hey, I got it working! I found a guy via twitter, and hired him. I need to figure out the styling, but at least it’s there, and he did it in a widget. Contact me and I’ll give you his e-mail.
    http://www.TraciBunkers.com/blog

    That’s awesome!!! I will contact you..

    Okay.. so for folks following this, using the iframes “appears” to work.. I’ve more testing to do before I can fully sign off on this which is why I say “appears” (your mileage may vary)..

    So let me update this thread with what I’ve been testing out.

    Following the Sideboxes Anywhere instructions (posted above) I created several files (1 for each sidebox I wanted to call) which contain similar code (this one is the categories sidebox zencart_categories.php):

    <?php
      $zcSBmodule = 'categories.php';
      $zcSBlayout = 'left';
      require ("/path/to/zencart/single_sidebox.php");
    ?>

    I wasn’t happy with the way iframes looked using the Text/PHP widget so I researched to find a suitable iframe plugin.

    IMHO, the iframed sideboxes, behave/look best when using the “Custom IFrame Widget” plugin. The downside of this plugin is that it hardcodes in the iframe border. I resolved this by editing the plugin to remove the iframe border from the plugin code. (removing it from the plugin code versus using CSS to drop the iframe borders will ensure a wider range of cross browser compatibility)

    I’m somewhat of a stickler for detail, and I wanted to make sure that sidebox “pages” will properly validate. So I added the following to my single_sidebox.php file at the VERY top of the file:

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="profile" href="http://gmpg.org/xfn/11" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title></title>
    </head>

    Just before the <title> opening and closing tags, you will need to add at least two more lines to your single_sidebox.php file.

    1. Some code so that links in the iframed sideboxes open where you would like (new window or same window)
    2. A link to the stylesheet which styles the sideboxes.

    Note: The site I’m building uses the WordPress template to “wrap” around Zen Cart so that Zen Cart and WordPress are styled alike. As a result, most of the store styles come from the WordPress theme’s stylesheet. The Zen Cart stylesheet only manages those style declarations which affect store specific IDs and classes.

    So for the site I’m working on, instead of linking the WordPress or Zen Cart stylesheets in my single_sidebox.php file, I created a “mini” Zen Cart “sideboxes only” stylesheet just for the Zen Cart iframed sideboxes. This “mini” stylesheet contains only the declarations I needed to style the sideboxes to match the rest of the site and is stored in my WordPress theme’s CSS folder. (The stylesheet contains declarations for links and images mostly — I did not need to use any of the Zen Cart sidebox IDs and classes at all)

    Another reason I created the “sideboxes only” stylesheet is so that I could use CSS to hide the Zen Cart sidebox titles without affecting the rest of the Zen Cart shop. (I instead used the WordPress widget title to create my sidebox titles for my iframed sideboxes)

    That’s it really..

    I even have it working with more than one sidebox. (It’s been reported on the Sideboxes Anywhere support thread that this was not possible – wanted to confirm that I had no issue getting more than one sidebox to display using the Sideboxes Anywhere method)

    Now there is a serious caveat to using iframed sideboxes:
    I have not tested iframed sideboxes with the shopping cart or login sideboxes yet. I am fairly certain that cookies and session settings will render some fairly gnarly results if these two particular sideboxes were iframed in.. I will be testing this over the weekend, and report back my findings.

    In the meantime if my testing pans out, I will go ahead and use this method to display my Zen Cart sideboxes inside WordPress for the site I am working on. IMHO however, iframed sideboxes feel more like a workaround solution versus a solid perm solution. So longer term, I think I will investigate having a proper Zen Cart sidebox plugin for WordPress developed. (oDesk, vWorker, or Elance are excellent sources for qualified developers and it’s where I’ll likely go for this work)

    Once I finish testing, I’ll post a link to the site I am working on so folks can see my end result.. 🙂 Wanted to post this to pass on the information to others..

    Wanted to add this..

    To further clarify my previous statements, I’m truly not advocating the use (or rather I should say the OVERUSE) of iframes at all for all the reasons most often cited (accessibility, page loading times, SEO, etc). However, without a proper plugin to render the sideboxes inside a WordPress widget, the iframes APPEAR to be a viable solution. However, it should be noted that iframes can cause issues that must be taken into account and mitigated if using this method. Again, this is why while I am cautiously optimistic about this method, I probably will eventually look into having a proper plugin developed to display Zen Cart sideboxes in a WordPress widget.

    That said, I believe that the limited use of an iframe will probably be okay.. I am using a notice of external content for screenreaders to resolve any accessibility issues, there are no serious SEO concerns from displaying 1 or 2 sideboxes, and I do not plan to load more than two iframed sideboxes on a page to ensure that I don’t create any performance issues.

    All this to say that I’m still testing this implementation and as of this writing I am cautiously optimistic that they will not be problematic down the road. I will of course update my findings if this turns out to NOT be the case..

    As it turns out, the fact that an iframe worked with this should have been the CLUE to the correct way to do this:

    My original include statement which used the local pathname looked like this:

    <?php
    include '/home2/mysite/public_html/shop/zencart-sidebox-categories.php';
    ?>

    So I changed my include statement to instead be included using a URL as follows:

    <?php
    include 'http://shop.mysite.com/zencart-sidebox-categories.php';
    ?>

    and BAM!!! It worked inside a Text/PHP widget!!! Which IMHO is the RIGHT way to do this.. No iframe needed at all!!! WHOO HOO!!! So now there are no SEO, validation, accessibility, performance, or any of the downsides to using iframes when other solutions exist.

    I kept the link to my “sidebox only” stylesheet in my single_sidebox.php file.. However now that I am not using an iframe to call my sideboxes I just need to confirm whether or not I need to include any HTML other than the CSS link to my sidebox stylesheet in my single_sidebox.php file.. Need to make sure that I don’t have validation/other issues if the only thing I add to my single_sidebox.php file is this:

    <head>
    <base href="http://shop.mysite.com/" />
    <link rel="stylesheet" type="text/css" href="http://shop.mysite.com/includes/templates/MY_TEMPLATE/css/sidebox_stylesheet.css" />
    </head>

    The base link is required so that images and other content which uses relative links will display correctly.

    Now I will be testing the crap out of this, but as it turns out I may not need to have a plugin developed at all.. 🙂 I will update this thread if I discover any issues (not anticipating any)…

    /* Begin Inside Joke */

    All in all this little “journey” only cost me $40.. **LOL**

    /* End Inside Joke */

    Wanted to share another thought here:
    As far as I am aware (and someone PLEASE correct me if I am wrong here) the way this add-on was INTENDED to be used is to make a call to a sidebox include file. The single_sidebox.php controls all the sideboxes. So it stands to reason that you should not be making a direct call to single_sidebox.php. While it works and you CAN call this file directly, it seems clear that this is not the way the author of this add-on intended this file to be used. Also if you are calling more than one sidebox, this is probably not a good practice.

    Okay.. so a few more refinements you will need to do as well..

    You will need to modify your Sideboxes Anywhere file(s) so that the sideboxes display at the same width as the sidebar widgets. Otherwise your Zen Cart sidebox content will be aligned funky inside your WordPress widget.

    There are two ways to achieve this.

    Since the sidebox include files call the single_sidebox.php file, you can update ALL your sidebox include files with one change. You would adjust the single_sidebox.php file by finding the following line:

    if (!isset($zcSBwidth)) $zcSBwidth = (isset($_GET['width'])) ? zen_db_input($_GET['width']) : 0;

    Modify the “0” value to match the width of your widget content (what’s INSIDE the widget which is NOT the same as the width of the widget itself). You may need to use the Firefox Developer Tool or a similar toolset to get the width of the widget content.

    What I mean whenI say content width:
    Content width = widget width less any left/right margins or padding.

    If you want to change the width of your individual sideboxes you would add the $zcSBwidth variable to your individual sidebox include file as follows:

    <?php
      $zcSBmodule = 'whats_new.php';
      $zcSBlayout = 'left';
      $zcSBwidth =200';
      require ("/home2/public_html/path_to_your_site/single_sidebox.php");
    ?>

    **spoke too soon**

    Need to delete this post to post an edited version….

Viewing 15 replies - 1 through 15 (of 53 total)
  • The topic ‘Display Zen Cart Sidebox inside Widget’ is closed to new replies.
Skip to toolbar