Forums / General Questions / blank sidebox

blank sidebox

Locked

Started by t0minit on 12 Nov 2007, 3:55 PM · Views: 5,307

Results 1 to 20 of 30
This thread is locked. New replies are disabled.
12 Nov 2007, 3:55 PM
#1
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

blank sidebox

Hi

Im using the blank sidebox mod. I want to put this PHP into my sidebox and in one of my divs but i cant! Anyone have any ideas? :mellow:

Cheers

<?php
	$header_cart = "<div id='header_cart'>"; 
  if ($_SESSION['cart']->count_contents() > 0) {
  $header_cart .= '<ul>' . "n";
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      $header_cart .= '<li>';

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $header_cart .= '<span class="cartNewItem">';
      } else {
        $header_cart .= '<span class="cartOldItem">';
      }

      $header_cart .= $products[$i]['quantity'] . BOX_SHOPPING_CART_DIVIDER . '</span><a class="font_green" href="' 

. zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']) . '">';

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $header_cart .= '<span class="cartNewItem">';
      } else {
        $header_cart .= '<span class="cartOldItem">';
      }

      $header_cart .= $products[$i]['name'] . '</span></a></li>' . "n";

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $_SESSION['new_products_id_in_cart'] = '';
      }
    }
    $header_cart .= '</ul>' . "n";
  } else {
    $header_cart .= '<div id="cartBoxEmpty">' . BOX_SHOPPING_CART_EMPTY . '</div>';
  }

  if ($_SESSION['cart']->count_contents() > 0) {
    $header_cart .= '<hr />';
    $header_cart .= '<div class="cartBoxTotal">' . $currencies->format($_SESSION['cart']->show_total()) . '</div>';
//    $header_cart .= '<br class="clearBoth" />';
  }

$header_cart .= "</div>";
echo $header_cart;  ?>
12 Nov 2007, 4:27 PM
#2
birdoasis avatar

birdoasis

Inactive

Join Date:
Jun 2005
Location:
Cheney WA
Posts:
1,123
Plugin Contributions:
0

Re: blank sidebox

You're saying that you can't, what happens when you try it?

Make sure you're in source code mode when working with the editor.

John Patrick
A Zen Cart Advocate!

12 Nov 2007, 5:05 PM
#3
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: blank sidebox

Thankyou for replying.

I am editing tpl_blank_sidebox.php in macromedia dreamweaver. My file is edited as below and i keep getting an unexpected t_string on line 108.

<?php
/**
 * blank sidebox - allows a blank sidebox to be added to your site
 *
 * @package templateSystem
 * @copyright 2007 Kuroi Web Design
  * @copyright Portions Copyright 2003-2007 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: blank_sidebox.php 2007-05-26 kuroi $
 */

  $content = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';

  // Replace the text and HTML tags between the apostophes on lines 19 and 20.
  // Use as many or as few lines using this model as you need for your custom content.
  // If you have a multilingual site define your text in the languages/YOUR_LANGUAGE/extra_definitions/blank_sidebox_defines.php and include it as shown in line 19.
  // If your site is monolingual, you can put the text right here as shown on line 20 (and nobody will know!)
  $content .= '';
  $content .= '
<head>
<style type="text/css">

body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}

h1 {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:16px;
}

p {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}

#sidecont{
width:190px;
margin:0px;
}

#cathed{
height:25px;
margin:auto;
background:url(http://computech-pcs.co.uk/images/t6.gif);
width:190px;
}

#splitter {
border-left:1px solid #CCCCCC;
border-right:1px solid #CCCCCC;
height:5px;
}

#catcont {
border-left:1px solid #CCCCCC;
border-right:1px solid #CCCCCC;
}

#footer {
border-left:1px solid #CCCCCC;
border-right:1px solid #CCCCCC;
background-color:#336699;
height:2px;
}

#contholder {
margin:auto;
width:150px;
border-bottom:1px dashed #CCCCCC;
padding:5px;
}

#cattitle {
margin-top:8px;
border-left:1px solid #CCCCCC;
border-right:1px solid #CCCCCC;
}

#cathed2{
height:25px;
margin:auto;
background:url(http://computech-pcs.co.uk/images/t6.gif);
width:190px;
}

.count {
color:#FF6600;
}



</style>
</head>

<body>

<div id="sidecont">
	<div id="cathed"></div>
	<div id="splitter"></div>
	<div id="catcont">
		<div id="contholder"><table width="150" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<?php
	$header_cart = "<div id='header_cart'>"; 
  if ($_SESSION['cart']->count_contents() > 0) {
  $header_cart .= '<ul>' . "n";
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      $header_cart .= '<li>';

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $header_cart .= '<span class="cartNewItem">';
      } else {
        $header_cart .= '<span class="cartOldItem">';
      }

      $header_cart .= $products[$i]['quantity'] . BOX_SHOPPING_CART_DIVIDER . '</span><a class="font_green" href="' 

. zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']) . '">';

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $header_cart .= '<span class="cartNewItem">';
      } else {
        $header_cart .= '<span class="cartOldItem">';
      }

      $header_cart .= $products[$i]['name'] . '</span></a></li>' . "n";

      if (($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $_SESSION['new_products_id_in_cart'] = '';
      }
    }
    $header_cart .= '</ul>' . "n";
  } else {
    $header_cart .= '<div id="cartBoxEmpty">' . BOX_SHOPPING_CART_EMPTY . '</div>';
  }

  if ($_SESSION['cart']->count_contents() > 0) {
    $header_cart .= '<hr />';
    $header_cart .= '<div class="cartBoxTotal">' . $currencies->format($_SESSION['cart']->show_total()) . '</div>';
//    $header_cart .= '<br class="clearBoth" />';
  }

$header_cart .= "</div>";
echo $header_cart;  ?>
	</td>
  </tr>
 
 </table></div>


</div>
	
	<div id="splitter"></div>
	<div id="footer"></div>
</div>

</body>
</html>
';

  $content .= '</div>';
?>
13 Nov 2007, 6:39 AM
#4
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: blank sidebox

come on someone must have a solution for this i have seen php in loads of these mods

13 Nov 2007, 9:17 AM
#5
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

Your PHP code is basically just a clone of the standard Zen Cart shopping cart sidebox with the gift vouchers code left out. If that's the only change you want to make, why not just comment out that code in the standard box?

The only other significant difference that I could see was that you have replaced the "\n" (new lines for formating your HTML) with "n" which will appear as output on your on your visitors' screens.

Why doesn't what you've done work? That's because your <?php tag that tells your server that this is where the PHP begins, is part of a string and therefore not recognised. You need a single apostrophe immediately before it to terminate the string and then a semi-colon to end that assignment, before you start your PHP.

Then you would need to make all the assignments within your PHP to $contents and not $header_cart, though you could just concatonate the two instead of echoing $header_cart (which is premature for a sidebox).

I've no idea why you're trying to put all this into a singe-celled table. That's just unnecessary, inflexible, makes for poor accessibility and will complicate future maintenance or changes.

Then you need to get those header and body tag pairs out. You've clearly just copied a whole page from Dreamweaver, but your Zen Cart page will already have those page-level tag pairs, adding another set in a sidebox will break your page.

Finally, all that CSS, some of which isn't relevant to the HTML that you're generating, but which will affect the rest of your site, should be removed to an external stylesheet which, with the right naming convention, can simply be placed in your template's css folder and it will be loaded automatically and correctly.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

13 Nov 2007, 9:52 AM
#6
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: blank sidebox

Its cuz i want my own image for the sidebox header i cannot do this without using the blank sidebox mod.

13 Nov 2007, 9:59 AM
#7
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

FAQ entry for using your own images for sidebox headers. Or if that's not exactly what you want, this FAQ entry, although for footers, would work equally well for headers

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

13 Nov 2007, 10:37 AM
#8
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: blank sidebox

Hi thanks for trying to help but i want a different image for each sidebox not just for left and right.

13 Nov 2007, 10:42 AM
#9
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

Then you would simply use the specific CSS IDs for each of the sideboxes rather than the generic classes for the all the right and left boxes ......

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

13 Nov 2007, 12:31 PM
#10
t0minit avatar

t0minit

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: blank sidebox

ok, what is the css id's for...

catergories
sponsors
new products
and shopping cart

cheers

3 Jan 2008, 10:03 PM
#11
qwerpoiu338 avatar

qwerpoiu338

New Zenner

Join Date:
Dec 2007
Location:
Ontario, Canada
Posts:
27
Plugin Contributions:
0

Re: blank sidebox

kuroi:

Why doesn't what you've done work? That's because your <?php tag that tells your server that this is where the PHP begins, is part of a string and therefore not recognised. You need a single apostrophe immediately before it to terminate the string and then a semi-colon to end that assignment, before you start your PHP.

Then you would need to make all the assignments within your PHP to $contents and not $header_cart, though you could just concatonate the two instead of echoing $header_cart (which is premature for a sidebox).

Greetings. Can someone please let me know how I can get PHP working within $content? I can't even show the following text within Blank Sidebox.

$content .= '';<?php echo "PHP SHOWN HERE"; ?> '<p>You can include text, links, images, HTML markup and even PHP code</p>';

I'm new to both HTML and PHP. Any help would be greatly appreciated.

3 Jan 2008, 10:13 PM
#12
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

@qwerpoiu338

You're already in PHP at the point that you're inserting PHP tags. And you're trying to insert your PHP after the end of statement marker (the semi-colon).

If you could provide the actual PHP that you want to insert, it will be possible to be more helpful.

If you just want to show the words PHP SHOWN HERE, then you code would be simply> content .= 'PHP SHOWN HERE';

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

3 Jan 2008, 10:47 PM
#13
qwerpoiu338 avatar

qwerpoiu338

New Zenner

Join Date:
Dec 2007
Location:
Ontario, Canada
Posts:
27
Plugin Contributions:
0

Re: blank sidebox

Thanks for your quick reply. Since I'm in the learning phase in PHP as I mentioned earlier. I don't have all the codes ready. My goal is to display some data from a varible passed from the blank_sidebox.php (from your instructions). So I'm trying to understand how and where I should place the PHP code within the $content variable for it to display properly (shown within the sidebox).

$content .= ' echo "PHP SHOWN HERE"; <p>You can include text, links, images, HTML markup and even PHP code</p>';

I tried removing the PHP tags but it will then treat all as HTML text and display "echo "PHP SHOWN HERE"" within the sidebox.

Could you please show me the proper way(or simple example) to insert PHP within $content?

4 Jan 2008, 7:09 AM
#14
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

@qwerpoiu338

As you are already inside some PHP tags, adding what's in your variable to $content (which contains the HTML that will be output in the sidebox is as simple as```php
$content .= $your_variable;

The dot in the .= is important as it appends $your_variable to the end of what is already in $content rather than replacing it.

If you also wanted to add some text around your content, you might use a construction such as```php
$content .= '<p>My variable value is: ' . $your_variable . '</p>';
```This would place $your_variable between two strings containing an opening paragraph tag, some text and a closing paragraph tag.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

4 Jan 2008, 5:26 PM
#15
qwerpoiu338 avatar

qwerpoiu338

New Zenner

Join Date:
Dec 2007
Location:
Ontario, Canada
Posts:
27
Plugin Contributions:
0

Re: blank sidebox

It's working!! Thanks.
I ran the following query from the database in the blank_sidebox.php file:

$query="SELECT field1, field2, field3
	FROM table
	ORDER by field1";
$results=mysql_query($query) or die(mysql_error());

Then I try to use the while loop to display each row from the $results variable in the tpl_blank_sidebox.php file:

  while ($row=mysql_fetch_array($results)) {		
                  $content .= $row['field1'].' '.$row['field2'].' '.$row['field3'].'<br/>';
          }

But it returned with the following warning:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource 

It seems like the $results variable from blank_sidebox.php didn't get passed onto tpl_blank_sidebox.php file. Did I miss some steps in between?

4 Jan 2008, 6:24 PM
#16
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

Debugging SQL is getting a bit off topic for a sidebox support thread. I'll say only that I would write this code using Zen Cart's database class and semantic XHTML as follows:

$query='select field1, field2, field3
 from ' . TABLE_NAME_CONSTANT . '
 order by field1';
$results=$db->Execute($query);
$content .= '<ul>';
while (!$results->EOF) {
 $content .= $results->fields['field1'] . ' ' . $results->fields['field2'] . ' ' . $results->fields['field3'];
}
constant .= '</ul>';
```where TABLE_NAME_CONSTANT is a constant defined in includes/database_tables.php

If you need SQL help beyond this, I recommend starting a new thread.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

5 Jan 2008, 9:28 PM
#17
qwerpoiu338 avatar

qwerpoiu338

New Zenner

Join Date:
Dec 2007
Location:
Ontario, Canada
Posts:
27
Plugin Contributions:
0

Re: blank sidebox

Thanks. Will start a new thread regarding this question.

14 Jan 2008, 10:52 PM
#19
tapper avatar

tapper

Zen Follower

Join Date:
Nov 2007
Location:
Upstate NY
Posts:
233
Plugin Contributions:
0

Re: blank sidebox

Just wanted to say THANKS for this mod!!

My company uses a couple different zen templates. The one from Monster Template is buggy, but at least it has all of the standard directories. I have the scrolling features sidebox working in that site.

The other one has NO directories under the template, and features and specials just go at the bottom of the center column. Nothing I did would make this template show my scrolling specials, or any standard features or specials sidebox.

Then I grabbed blank sidebox, renamed everything in the code and filenames to "custom_specials_box". I put the database calls and randomizer in one file, changed text in a few places, passed my variables to the marquee tag and it worked the first time. This is the most php I've ever coded and I am just thrilled.

So you can all take a break now. I'll write Zen Cart 1.4 for you and let you know when I'm finished. :laugh:

14 Jan 2008, 11:55 PM
#20
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: blank sidebox

Tapper:

Then I grabbed blank sidebox, renamed everything in the code and filenames to "custom_specials_box". I put the database calls and randomizer in one file, changed text in a few places, passed my variables to the marquee tag and it worked the first time. This is the most php I've ever coded and I am just thrilled.

So you can all take a break now. I'll write Zen Cart 1.4 for you and let you know when I'm finished. :laugh:You get this mod. This is exactly what it's intended for - being used as a Zen Cart-compliant framework into which you can insert your choice of code.

Working first time is always a good result. I'll look forward to seeing your Zen Cart 1.4. I'll be here for the next few hours :D

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)