Display Zen Cart Sidebox inside Widget
-
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: https://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: https://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..
-
Correction on this part:
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.The BETTER answer is to set your Zen Cart sidebox width to match your widget title width. (this MAY be the same width as your sidebar — depends on your template’s stylesheet) Again, if you don’t know what this is, you can use the Firefox Developer Tool (or a similar toolset) to help you get this answer..
More corrections to what I wrote previously:
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="https://shop.mysite.com/" /> <link rel="stylesheet" type="text/css" href="https://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.
I got rid of the <head> tags altogether. They aren’t required. (they never were) I knew better than to do this, I but let a “so-called” PHP expert talk me into doing it this way.. Since I didn’t SEE any errors, and the sideboxes appeared to work, I thought “no harm, no foul”..
However, when I was troubleshooting other things in my Zen Cart store, I checked the error logs only to discover that the code at the top of my single_sidebox.php file was causing Zen Cart to generate HUNDREDS of “headers already sent” error logs in Zen Cart.. (1 error log for every sidebox I displayed everytime I refreshed the page) as I suspected all along this code does cause errors on the Zen Cart side..
So I removed the<head> tags and moved the remaining lines to the BOTTOM of the single_sidebox.php file (after the “?>”). So all that you see at the bottom of my single_sidebox.php file is this:
<base href="https://shop.mysite.com/" /> <link rel="stylesheet" type="text/css" href="https://shop.mysite.com/includes/templates/MY_TEMPLATE/css/sidebox_stylesheet.css" />
And everything still works as it should and there are NO MORE error messages in the Zen Cart error logs..
More information..
As I suspected, using the shopping cart and login sideboxes with Sideboxes Anywhere does generate errors in Zen Cart.
A quick look at my Zen Cart cache folder after viewing the URL for the the login sidebox page showed an error log was generated which contained the following:
[29-Dec-2011 09:41:40] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/functions/sessions.php on line 114
[29-Dec-2011 09:41:40] PHP Warning: Cannot modify header information – headers already sent by (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/init_includes/init_templates.php on line 78The shopping cart sidebox page generated an error log as well:
[29-Dec-2011 09:46:04] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/functions/sessions.php on line 114
[29-Dec-2011 09:46:04] PHP Warning: Cannot modify header information – headers already sent by (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/init_includes/init_templates.php on line 78The point here is that in my testing the Sideboxes Anywhere code works just fine for the following sideboxes:
- Search
- New Products
- Specials
- Featured Products
- Categories
- Best Sellers
I’m sure it works with other sideboxes as well.. But it appears that any sideboxes which have session information like the login or shopping cart sideboxes will generate errors.
For anyone who needs the login or shopping cart sideboxes to display in WordPress, you will probably have to seek the services of a qualified developer to get the code for sessions correct. Personally I think it’s debatable whether or not login or shopping cart info needs to be displayed in WordPress..
I’m going to start a new thread to summarize what I’ve done.. I’m done with my implementation. Hope someone else finds this information useful..
Summary of My Findings
You will need to use the Zen Cart add-on called Sideboxes Anywhere..
You will need to following these instructions to create the files needed for this to all work. You need to test all your sidebox call files to make sure they work and display the sidebox you want it to display.
This thread will not address any specific issues with configuring the Zen Cart Sideboxes Anywhere add-on. Issues with configuring the Sideboxes Anywhere add-on should be posted on the Zen Cart support forums.
Please read Tip 3 before you begin. It provides information with regards to sideboxes which rely on sessions. (login or shopping cart sideboxes)
Once you have the Sideboxes Anywhere add-on setup, then here’s what you need to do to display your Zen Cart sideboxes inside a WordPress widget.
- You will need a plugin like the Executable PHP widget. You cannot use a plain text widget.
- At the BOTTOM of the single_sidebox.php file (after the “?>”) add this:
<base href="https://shop.mysite.com/" /> <link rel="stylesheet" type="text/css" href="https://shop.mysite.com/includes/templates/MY_TEMPLATE/css/sidebox_stylesheet.css" />
The base link is required so that images and other content which uses relative links will display correctly. The stylesheet link helps with styling the sideboxes.
Tip: 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 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.
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)
- Using the PHP/Text widget plugin add a PHP/Text widget which contains the following code:
<?php include 'https://shop.mysite.com/zencart-sidebox-categories.php'; ?>
You will additional PHP/Text widgets for each sidebox you wish to display. Remember if you followed the Sideboxes Anywhere instructions you will have created one file for each sidebox you wish to “widgetize”.
Notes/Tips:
Tip 1
Sideboxes Anywhere 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.Tip 2
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 sidebox header.
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"); ?>
Tip 3
As I suspected, using the shopping cart and login sideboxes with Sideboxes Anywhere does generate errors in Zen Cart.A quick look at my Zen Cart cache folder after viewing the URL for the the login sidebox page showed an error log was generated which contained the following:
[29-Dec-2011 09:41:40] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/functions/sessions.php on line 114
[29-Dec-2011 09:41:40] PHP Warning: Cannot modify header information – headers already sent by (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/init_includes/init_templates.php on line 78The shopping cart sidebox page generated an error log as well:
[29-Dec-2011 09:46:04] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/functions/sessions.php on line 114
[29-Dec-2011 09:46:04] PHP Warning: Cannot modify header information – headers already sent by (output started at /home2/yoursite/public_html/shop/single_sidebox.php:6) in /home2/yoursite/public_html/shop/includes/init_includes/init_templates.php on line 78The point here is that in my testing the Sideboxes Anywhere code works just fine for the following sideboxes:
- Search
- New Products
- Specials
- Featured Products
- Categories
- Best Sellers
I’m sure it works with other sideboxes as well.. But it appears that any sideboxes which have session information like the login or shopping cart sideboxes will generate errors.
For anyone who needs the login or shopping cart sideboxes to display in WordPress, you will probably have to seek the services of a qualified developer to get the code for sessions correct. Personally I think it’s debatable whether or not login or shopping cart info needs to be displayed in WordPress..
Dev site I’ve been working on with the Zen Cart sidebox widgets in place..
http : // clientyourplateormineinc . overthehillweb . com/I was very excited by what you figured out. I’m not sure if I’ve done something wrong, but when I put in the widget, and the code for it, it messes up my blog.
I wonder if it has to do with my WP theme. I’ve had to make a lot of changes to it so that other things would work. I’m using the Minibox for WordPress (Black) 1.1 theme.
Well, I just previewed a different theme, and it broke it too. So maybe the theme isn’t the issue.
Without anything more descriptive than “it messes up my blog” or “it broke it too” it’s hard to say what might have happened.. Some details would help..
The best way to show what happened is probably with a screen shot. Here’s what it looks like without the PHP widget.
And here’s what it looks like with the php widget in the right column, right under the picture of the book. The heading shows up, but nothing after it. Plus the white background is gone along with the posts.
I’m using the widget you suggested. The code I have in it is
<?php include 'https://www.tracibunkers.com/zen_whats_new_sidebox.php'; ?>
I’ve got the zen_whats_new_sidebox.php file in my public folder. Here’s the file:
<?php $zcSBmodule = 'whats_new.php'; $zcSBlayout = 'right'; define('DIR_WS_IMAGES' , 'https://www.tracibunkers.com/zen/images/'); require ('/home/tracibu/public_html/zen/single_sidebox.php'); ?>
At the bottom of my single_sidebox.php file, I have this:
<base href="https://www.TraciBunkers.com/" /> <link rel="stylesheet" type="text/css" href="https://www.TraciBunkers.com/zen/includes/templates/cherry_zen/css/stylesheet.css" />
I also set the column width to 180, which is the width of my right sidebar.
If you go to https://www.tracibunkers.com/zen_whats_new_sidebox.php the images don’t show up, just the text. If you go to https://www.tracibunkers.com/zen/single_sidebox.php they do.
Any ideas what I have done wrong?
Off the top of my head I’d say mostly everything looks correct.. However, this line in your zen_whats_new_sidebox.php is probably not necessary:
define(‘DIR_WS_IMAGES’ , ‘https://www.tracibunkers.com/zen/images/’);
Also I’d take a look at your Zen Cart cache folder and see what the last few error logs read.. They might contain a clue as to the issue.. To be VERY sure, I’d delete the log files and try refreshing your page to see if an error log is generated by your code..
Took me 5 minutes to implement this on another site with a COMPLETELY different template setup (one site uses Catalyst template framework, the other is an Artisteer generated template). It worked first time out (no error logs generated either)..
So I took another look at how you set things up.. (links are MUCH MORE helpful than screenprints for troubleshooting BTW..)
The base href URL at the bottom of your single_sidebox.php file should be the URL for your store.. (Hence why the images don’t show up)
I changed the base href from https://www.tracibunkers.com to https://www.tracibunkers.com/zen and the images still don’t show up.
I took out the line you mentioned:
define('DIR_WS_IMAGES' , 'https://www.tracibunkers.com/zen/images/');
I had originally put it there because I had read it was needed for the images to show. But with & without it’s not making a difference.I checked my zen cart error log, made 2 changes to the single_sidebox.php file and that got rid of any errors. But, I’m still not having any luck with it working on my blog. I have tried putting this:
<?php include 'https://www.tracibunkers.com/zen/single_sidebox.php'; ?>
and this:
<?php include 'https://www.tracibunkers.com/zen_whats_new_sidebox.php'; ?>
into the php widget and I have the same problem. I tried putting the widget on the left sidebar just to see if it made a difference, but had the same problem with everything after the sidebox heading not showing up, along with no white background or posts.
I went to my cPanel to read the error log there. When I call the single_sidebox directly, I only get these errors:
[Mon Jan 02 12:33:49 2012] [error] [client 66.219.58.44] File does not exist: /home/tracibu/public_html/404.shtml
[Mon Jan 02 12:33:49 2012] [error] [client 66.219.58.44] File does not exist: /home/tracibu/public_html/robots.txtWhen I call the sidebox through zen_whats_new_sidebox.php, I get more errors, relating to the zen_whats_new_sidebox.php:
[Mon Jan 02 12:49:06 2012] [error] [client 66.249.72.5] File does not exist: /home/tracibu/public_html/404.shtml
[Mon Jan 02 12:49:06 2012] [error] [client 66.249.72.5] File does not exist: /home/tracibu/public_html/zen/bonkersheadquarters1965/backups/dump
[Mon Jan 02 12:47:09 2012] [error] [client 71.201.124.118] File does not exist: /home/tracibu/public_html/404.shtml, referer: https://www.tracibunkers.com/workshops/workshops.htm
[Mon Jan 02 12:47:09 2012] [error] [client 71.201.124.118] File does not exist: /home/tracibu/public_html/workshops/favicon.ico, referer: https://www.tracibunkers.com/workshops/workshops.htm
[Mon Jan 02 12:45:59 2012] [error] [client 65.52.110.199] File does not exist: /home/tracibu/public_html/404.shtml
[Mon Jan 02 12:45:59 2012] [error] [client 65.52.110.199] File does not exist: /home/tracibu/public_html/robots.txt
[Mon Jan 02 12:45:25 2012] [error] [client 208.115.111.75] File does not exist: /home/tracibu/public_html/404.shtml
[Mon Jan 02 12:45:25 2012] [error] [client 208.115.111.75] File does not exist: /home/tracibu/public_html/robots.txt
[Mon Jan 02 12:44:47 2012] [error] [client 24.143.56.215] File does not exist: /home/tracibu/public_html/404.shtml, referer: https://www.tracibunkers.com/zen_whats_new_sidebox.php
[Mon Jan 02 12:44:47 2012] [error] [client 24.143.56.215] File does not exist: /home/tracibu/public_html/bmz_cache, referer: https://www.tracibunkers.com/zen_whats_new_sidebox.php
[Mon Jan 02 12:43:39 2012] [error] [client 24.143.56.215] File does not exist: /home/tracibu/public_html/404.shtml, referer: https://www.tracibunkers.com/zen_whats_new_sidebox.php
[Mon Jan 02 12:43:39 2012] [error] [client 24.143.56.215] File does not exist: /home/tracibu/public_html/bmz_cache, referer: https://www.tracibunkers.com/zen_whats_new_sidebox.php
[Mon Jan 02 12:42:45 2012] [error] [client 88.131.106.6] File does not exist: /home/tracibu/public_html/404.shtml
[Mon Jan 02 12:42:45 2012] [error] [client 88.131.106.6] File does not exist: /home/tracibu/public_html/robots.txtSo, I’m not exactly sure what the problem is. I even uploaded a clean single_sidebox.php file, then pasted the the base hfref link at the bottom.
If there is a link I should post that will help, let me know!
Oh, one tiny bit of success. I got the images to show up at https://www.tracibunkers.com/zen_whats_new_sidebox.php
I added a / after zen. so now at the very bottom of my single_sidebox.php file, I have:
<base href="https://www.TraciBunkers.com/zen/" />
I know throwing everything against the wall to see what sticks is a technique often used to solve a problem, but we’re no longer trying to figure out what the solution is. We’re trying to get the tested solution working for you. Please remove any code that is not part of the solution I outlined, and let’s move forward to see if we can figure out what’s wrong here..
I changed the base href from https://www.tracibunkers.com to https://www.tracibunkers.com/zen and the images still don’t show up.
As I see you discovered later, you need the ending “/”. (In my summary post my sample code includes the ending “/”)
I took out the line you mentioned:define(‘DIR_WS_IMAGES’ , ‘https://www.tracibunkers.com/zen/images/’); I had originally put it there because I had read it was needed for the images to show. But with & without it’s not making a difference.
This line does not work which is why I suggested removing it.. It should NOT be in your code or else this adds a new factor to the troubleshooting process which makes it hard to get down to the bottom of why my solution isn’t working for you..
Try changing the code in your PHP widget to this:
<?php include (home_url( '/' ) . 'zen_whats_new_sidebox.php'); ?>
if that doesn’t work (though it SHOULD work) use this code:
<?php include ('https://www.tracibunkers.com/zen_whats_new_sidebox.php'); ?>
DO NOT make a direct call to single_sidebox.php that’s NOT how the single_sidebox.php file in Sideboxes Anywhere was intended to be used. Again, it adds a new factor to the troubleshooting process which makes it difficult to access the issue..
- The topic ‘Display Zen Cart Sidebox inside Widget’ is closed to new replies.