Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

See how many items are in the cart, if this many, show that image


hodja451

Recommended Posts

I want to say, "see how many items are in the cart, if this many, show that image".

 

I used the box/shopping_cart.php as a foundation. I relied on

if ($cart->count_contents() > 0) 

butI ended up with a PHP Fatal error: Can't use method return value in write context

 

I need 2 images to change, that's why there are 2 blocks. Also, there are image maps attached to the image, so instead of having different image names, I used the same name in different locations.

 

Here is my attempt:

 

<?php
/*
 $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/
?>
<!-- shopping_cart //-->         

<?php
 $cart_contents_string = '';
 if ($cart->count_contents() < 1) {
   $cart_contents_string = '<img src="images/cartcount/0/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 1) {
   $cart_contents_string = '<img src="images/cartcount/1/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 2) {
   $cart_contents_string = '<img src="images/cartcount/2/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 3) {
   $cart_contents_string = '<img src="images/cartcount/3/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 4) {
   $cart_contents_string = '<img src="images/cartcount/4/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 5) {
   $cart_contents_string = '<img src="images/cartcount/5/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 6) {
   $cart_contents_string = '<img src="images/cartcount/6/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 7) {
   $cart_contents_string = '<img src="images/cartcount/7/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 8) {
   $cart_contents_string = '<img src="images/cartcount/8/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 9) {
   $cart_contents_string = '<img src="images/cartcount/9/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() = 10) {
   $cart_contents_string = '<img src="images/cartcount/10/204b.jpg" width="304" height="27" border="0" />';
 if ($cart->count_contents() > 10) {
   $cart_contents_string = '<img src="images/cartcount/over10/204b.jpg" width="304" height="27" border="0" />';

?>
           </td>
		<td colspan="2"><img src="images/303.jpg" width="185" height="11" alt=""></td>			
         </tr>

	  <tr height="15">
	    <td><a href="account.php"
			onmouseover="changeImages('id305', 'images/305over.jpg'); return true;"
			onmouseout="changeImages('id305', 'images/305.jpg'); return true;">
			<img name="id305" src="images/305.jpg" width="95" height="15" border="0" alt="My Account" title=" My Account " ></a></td>
		<td rowspan="7"><img src="images/304.jpg" width="90" height="109" alt=""></td>
	  </tr>

         <tr height="1">
	    <td rowspan="2"><a href="checkout_shipping.php"
			onmouseover="changeImages('id306', 'images/306over.jpg'); return true;"
		    onmouseout="changeImages('id306', 'images/306.jpg'); return true;">
			<img name="id306" src="images/306.jpg" width="95" height="14" border="0" alt="Checkout" title=" Checkout "></a></td>
	  </tr>

	  <tr height="13" valign="top">
           <td rowspan="5" valign="top"><div style="position: absolute;">
		<!-- search //-->
            <table border="0" width="65" cellspacing="0" cellpadding="0" valign="top">
             <tr valign="top">
              <td valign="top"><img src="images/pixel_trans.gif" width="2" height="1" border="0" /></td>
             <td align="left" valign="top"><form name="quick_find" action="http://127.0.0.1/catalog/advanced_search_result.php" method="get"><input type="text" name="keywords" size="20" maxlength="40"></td>
              <td valign="top"><input type="image" src="images/pixel_trans.gif" alt="Go!" width="40" height="30" border="0" /><br><a href="http://127.0.0.1/catalog/advanced_search.php"></a></form></td>
             </tr>
            </table>
           <!-- search_eof //-->
		</div>
<?php
 $cart_contents_string = '';
 if ($cart->count_contents() < 1) {
   $cart_contents_string = '<img src="images/cartcount/0/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 1) {
   $cart_contents_string = '<img src="images/cartcount/1/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 2) {
   $cart_contents_string = '<img src="images/cartcount/2/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 3) {
   $cart_contents_string = '<img src="images/cartcount/3/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 4) {
   $cart_contents_string = '<img src="images/cartcount/4/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 5) {
   $cart_contents_string = '<img src="images/cartcount/5/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 6) {
   $cart_contents_string = '<img src="images/cartcount/6/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 7) {
   $cart_contents_string = '<img src="images/cartcount/7/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 8) {
   $cart_contents_string = '<img src="images/cartcount/8/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 9) {
   $cart_contents_string = '<img src="images/cartcount/9/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() = 10) {
   $cart_contents_string = '<img src="images/cartcount/10/204c.jpg" width="304" height="93" border="0" />';
 if ($cart->count_contents() > 10) {
   $cart_contents_string = '<img src="images/cartcount/over10/204b.jpg" width="304" height="93" border="0" />';

?>
<!-- shopping_cart_eof //-->

 

 

Any advice would be greatly appreciated. I'm very new at this and may not understand an answer that's too general. Links to an explanation would be great too.

 

Thanks,

Walter

My experience relates to osCommerce Online Merchant v2.2 RC2

Link to comment
Share on other sites

This code:

 

<?php
 if ( $cart->count_contents() <= 10) {
   $cart_contents_string =  sprintf("<img src=\"images/cartcount/%d/204b.jpg\" width=\"304\" height=\"27\" border=\"0\" />"  , $cart->count_contents() );
 } else {
   $cart_contents_string = '<img src="images/cartcount/over10/204b.jpg" width="304" height="27" border="0" />';
 }
?>

Similarly this code:

 

<?php
 if ( $cart->count_contents() <= 10) {
   $cart_contents_string =  sprintf("<img src=\"images/cartcount/%d/204c.jpg\" width=\"304\" height=\"93\" border=\"0\" />"  , $cart->count_contents() );
 } else {
   $cart_contents_string = '<img src="images/cartcount/over10/204c.jpg" width="304" height="93" border="0" />';
 }
?>

I think that will work.

 

BACKUP WHAT YOU HAVE BEFORE ATTEMPTING ANY EDITS.

 

I really don't have links to explain what I did.

:blush:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Thanks for the code! It looks really good, but I think there may have been a self explanatory part that I just didn't know. I probably did it wrong. I put it directly into a table, the only content of a td, I didn't add anything. While it returns no errors, and no image, a check of the output shows an empty cell. It seems it just didn't write it, so that's why I think there may have been a self explanatory part that I just didn't know. Should I have nested that code within something other than an empty cell?

 

And thanks again!

My experience relates to osCommerce Online Merchant v2.2 RC2

Link to comment
Share on other sites

Well....

 

You went thru the trouble building $cart_contents_string (twice), but you've neglected to output it to the browser (twice) like :

 

<?php
 echo $cart_contents_string;
?>

:blush:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

I can't thank you enough for responding so quickly. Don't be fooled by my original code, I have no idea what I'm doing. What I have/had done is to just set it up to swap one image with the first code you provided, I figured if I get that to work, I'll try to add the second one. Thing is, I didn't neglect to output twice, I neglected to output even once! Based on your last note, I tried 4 combos, and it finally worked!!

 

For other newbies:

 

I removed

<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>

from index.php

 

I took

require(DIR_WS_BOXES . 'shopping_cart.php');

 

from within column_right.php, and I converted it to

<td rowspan="3"><?php require(DIR_WS_BOXES . 'shopping_cart.php'); ?></td>

 

and placed it where the image belongs in index.php

 

I then used this to replace everything within boxes/shopping_cart.php

 

<?php
/*
 $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/
?>
<!-- shopping_cart //-->
<?php
 $cart_contents_string = '';
 if ( $cart->count_contents() <= 10) {
$cart_contents_string = sprintf("<img src=\"images/cartcount/%d/204b.jpg\" width=\"304\" height=\"27\" border=\"0\" />" , $cart->count_contents() );
} else {
$cart_contents_string = '<img src="images/cartcount/over10/204b.jpg" width="304" height="27" border="0" />';
}
echo $cart_contents_string;  
?>
<!-- shopping_cart_eof //-->

 

WORKS PERFECT!!!!

 

I'm off to make it change 2 images.

Thanks,

Thanks,

Thanks,

Walter

My experience relates to osCommerce Online Merchant v2.2 RC2

Link to comment
Share on other sites

They both work perfectly. I'm very anxious to show Germ what he allowed me to do, and share the concept with others. I had put a placeholder page at www.instantvideogames.com it is a simple html page for now, but I assure you, with the above code, Germ has allowed me to make that digital counter image actually work. Take a look.

 

FYI, the only way I was able to get the search box to line up, was to cut the image at the top left corner of the search box. Therefore, my digital counter image is cut in 2 pieces, top/bottom, not first digit/second digit as one would assume. Instead of one include with both images and the tds between as in my first post, I just created Shopping_cart1.php and Shopping_cart2.php.

 

I will post again when the page is live so others can put an item or 3 in the cart and watch it work, and or view the code. For now you can look at the image and imagine the possibilities Germ has allowed us.

 

Many thanks,

Walter (a game seller doing this himself, not the game sellers 'web guy')

My experience relates to osCommerce Online Merchant v2.2 RC2

Link to comment
Share on other sites

  • 4 weeks later...

It's fully functional and posted. If you go to www.instantvideogames.com and add items to the cart, you will see the image of the digital counter change. I think it's awsome, thanks, Germ.

 

Walter

My experience relates to osCommerce Online Merchant v2.2 RC2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...