Zen Cart Logo
Forums / General Questions / Showing cart items

Showing cart items

Locked

Views: 1,981

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
16 May 2008, 4:26 AM
#1
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Showing cart items

I have my cart contents displaying in the header via a jQuery mouseover balloon. It currently displays the number of items in the cart and total. I would like to add the qty and item name as well. Similar to how it displays in the cart sidebox, but truncating it with a "more" link if more than 3 line items. Can someone help?

Here is my code:

<table border=0 cellpadding=0 width=180 height=100% align=center>
	<tr>
		<td valign=top><strong>Your Cart:</strong><br><?php echo sizeof($_SESSION['cart']->get_products()); ?> Item(s):
 	<?php $header_cart = $currencies->format($_SESSION['cart']->show_total());  
	echo $header_cart;
	?></td>
	</tr>
	</table>

I appreciate any help. I'm racking my brain trying to figure it out. :bangin:

20 May 2008, 11:48 PM
#2
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

anyone?

22 May 2008, 10:21 PM
#3
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

Still coming up empty :-/

27 May 2008, 5:15 PM
#4
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

I have my cart contents displaying in the header via a jQuery mouseover balloon. It currently displays the number of items in the cart and total, such as 5 Items | $24.75. I would like to add the qty and item name as well. Similar to how it displays in the cart sidebox, but truncating it with a "more" link if more than 3 line items.

For example:
**1 x Test Item
2 x Test Item2
1 x Test Item3
more...

5 Items: $24.75**

Can someone help?

Here is my code:

<table border=0 cellpadding=0 width=180 height=100% align=center>
    <tr>
        <td valign=top><strong>Your Cart:</strong><br><?php echo sizeof($_SESSION['cart']->get_products()); ?> Item(s):
     <?php $header_cart = $currencies->format($_SESSION['cart']->show_total());  
    echo $header_cart;
    ?></td>
    </tr>
    </table>

I appreciate any help. I'm racking my brain trying to figure it out.

27 May 2008, 7:01 PM
#5
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

ok here's an update. I borrowed code from tpl_checkout_confirmation_default and it does the trick, however, it doesnt grab the variables until we get to step 1 of 3 of the checkout. If someone is just viewing their cart or just shopping, the items are missing. I know that I probably need to pass the variables, but I'm unsure how. Here's my updated code:

<table cellpadding=0 cellspacing=0>
		<?php for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { ?>
        <tr>
          <td class="bubbleCartItems"><?php echo $order->products[$i]['qty']; ?> x <?php echo $order->products[$i]['name']; ?></td>
      </tr>
	  <?php  }  // end for loopthru all products ?>
      </table>

I also need to figure out how to cap this at only listing 3 items and show a "more..." link.

27 May 2008, 9:56 PM
#6
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

In case anyone wants a look, it's over at www.cutiecardcreations.com/index.php. Mouseover the View Cart link at the top right. It's blank until you get to the checkout process.

27 May 2008, 10:40 PM
#7
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,621
Plugin Contributions:
0

Re: Showing cart items

Moderator's Note: The 2 threads for the same topic have been merged.

17 Jun 2008, 10:35 PM
#8
guls_guys avatar

guls_guys

New Zenner

Join Date:
Apr 2008
Posts:
25
Plugin Contributions:
0

Re: Showing cart items

hi

i was trying to achieve same thing and i have got it with this little piece of code

<!-- $productArray array has every thing in it related to whole shopping cart-->
<!-- un comment print_r and get any thing you want from this array-->
  <?php //print_r ($productArray);
  foreach($productArray as $product)
  {
  $proName=$product['productsName'];
  $proPriceEach=$product['productsPriceEach'];
  //print_r ($proName);
  //print_r ($proPriceEach);
  echo "<div id=\"balloonProName\">$proName</div>";
  echo "<div id=\"balloonProPriceEach\">$proPriceEach</div>";
  }
  ?>

then display these divs in the balloon div.
i have used http://demos111.mootools.net/Tips for balloon tooltip or you can chose from many other
like
http://php-ajax-code.blogspot.com/2007/07/23-best-ajax-tooltip-and-balloon.html

hope this helps

regards
salman

17 Jun 2008, 11:19 PM
#9
fbords avatar

fbords

New Zenner

Join Date:
Sep 2007
Posts:
60
Plugin Contributions:
0

Re: Showing cart items

guls_guys thanks for the reply.

Unfortunately, your code is just a different method to what I already have. My problem is that I can only show the number of items in the balloon until I reach the checkout. Only then for some reason will my detailed items show. The same thing happens with your code.

Here is an updated version of what I have:

<table border="0" cellspacing="0" cellpadding="2" width="180" height="100%" align="center">
	<tr>
		<td valign=top height="15"><strong>Your Cart:</strong><br>
		<!-- START CART ITEMS -->
		<table cellpadding=0 cellspacing=0>
		<?php for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { ?>
        <tr>
          <td class="bubbleCartItems"><?php echo $order->products[$i]['qty']; ?> x <?php echo $order->products[$i]['name']; ?></td>
      </tr>
	  <?php  }  // end for loopthru all products ?>
      </table>
	  <!-- END CART ITEMS -->
		</td>
	</tr>
	<tr>
		<td align=right>		
		<?php echo sizeof($_SESSION['cart']->get_products()); ?> Item(s):
 	<?php $header_cart = $currencies->format($_SESSION['cart']->show_total());  
	echo $header_cart;
	?></td>
	</tr>
	</table>
23 Jun 2008, 9:29 AM
#10
guls_guys avatar

guls_guys

New Zenner

Join Date:
Apr 2008
Posts:
25
Plugin Contributions:
0

Re: Showing cart items

yes i agree
this is happening because php data is not loading in tooltip.

i am working on it, as soon as available i will post it.
one solution could be using ajax to load an external page in tooltip.

so fingers crossed

salman

23 Jun 2008, 12:55 PM
#11
guls_guys avatar

guls_guys

New Zenner

Join Date:
Apr 2008
Posts:
25
Plugin Contributions:
0

Re: Showing cart items

Hi

guys i have added this code in "my_template/common/tpl_header.php"

  <table width="95%" border="1" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC">
  
  <?php
  foreach($productArray as $product)
  {
  $proName=$product['productsName'];
  $proPriceEach=$product['productsPriceEach'];
  $proImg=$product['productsImage'];
  $proQty=$product['showFixedQuantityAmount'];
  $proAttribs=$product['attributes'];
  ?>
  <tr>
  		<td colspan="5"><?php echo $proName;?></td>
  </tr>

  <tr>
  	<td rowspan="2" id="balloonProImg">
	<?php 
	$src=htmlentities($proImg,ENT_NOQUOTES);
	$s = explode(" ", $src);
	$s =explode ("=",$s[1]);
	$img= $s[1];
	$pat = '/(^"+|"+$)/';
	$imgWOQ=preg_replace( $pat, '', $img );
	$imgWH = getimagesize($imgWOQ);
	$percent=0.10;//10%
	$width=round($imgWH[0]*$percent);
	$height=round($imgWH[1]*$percent);
	echo "<img src=\"$imgWOQ\" width=\"$width\" height=\"$height\"/>";
	?> 
    </td>
    <td>Qty</td>
    <td>Color</td>
    <td>Size</td>
    <td>Total</td>
  </tr>
  
  <tr>
    <td><?php echo $proQty;?></td>
	<?php 
    $count=count($proAttribs);
	for($i=1; $i<=$count; $i++)
		{
			$allAttribs=$proAttribs[$i];
			//print_r($indProduct);
			$productOption=$allAttribs[products_options_name];
			$productVal=$allAttribs[products_options_values_name];
			//echo $productVal;
			echo "<td >$productVal</td>";
		}
	?>
  <td><?php echo $proPriceEach; ?></td>
  </tr>
  <tr><td> </td></tr>
  <?php
  }
  ?>
  </table>

this code display all the items in the cart in a table but
i cannot view its output on any of the pages. For example when i click home i cant see this table in header and same is the case with other pages. i can only see this table output in header when i click on shopping cart.

i want to display this table in header all the time regardless of the page user is viewing just like the logo in header displays all the time.

is it about overriding any thing? i am confused on this:cry::frusty:.
can any one suggest any thing.

salman

24 Jun 2008, 9:07 AM
#12
guls_guys avatar

guls_guys

New Zenner

Join Date:
Apr 2008
Posts:
25
Plugin Contributions:
0

Re: Showing cart items

Hi

the simplist solution is to pass this productArray to $_session array in

tpl_shopping_cart_default.php
$_SESSION['tip']=$productArray;

in tpl_header.php
if($_SESSION['tip']=='')
{
echo 'Your Shopping Bag is Empty';
}
else
{
$tempProduct=$_SESSION['tip'];
}

i am not sure if its safest of the ways but it works
and solves ur problem of not able to see the actual contents of the cart when u r on other pages then cart page its self.

hope this can invite some other people to this thread for sharing their ideas

regards
salman

25 Jun 2008, 9:47 AM
#13
guls_guys avatar

guls_guys

New Zenner

Join Date:
Apr 2008
Posts:
25
Plugin Contributions:
0

Re: Showing cart items

hi got it working now

do these changes in following files

add this code to header_php.php
in here
zen\includes\modules\pages\shopping_cart
afte line 162 with in the loop.

$_SESSION['tip'][$i] = array('attributeHiddenField'=>$attributeHiddenField,
                            'flagStockCheck'=>$flagStockCheck,
                            'flagShowFixedQuantity'=>$showFixedQuantity,
                            'linkProductsImage'=>$linkProductsImage,
                            'linkProductsName'=>$linkProductsName,
                            'productsImage'=>$productsImage,
                            'productsName'=>$productsName,
                            'showFixedQuantity'=>$showFixedQuantity,
                            'showFixedQuantityAmount'=>$showFixedQuantityAmount,
                            'showMinUnits'=>$showMinUnits,
                            'quantityField'=>$quantityField,
                            'buttonUpdate'=>$buttonUpdate,
                            'productsPrice'=>$productsPrice,
                            'productsPriceEach'=>$productsPriceEach,
                            'rowClass'=>$rowClass,
                            'buttonDelete'=>$buttonDelete,
                            'checkBoxDelete'=>$checkBoxDelete,
                            'id'=>$products[$i]['id'],
                            'attributes'=>$attrArray);

by adding this code you will have whole product array in your session array and you can access this any where in the cart.

now you have to access this array in header so in tpl_header.php
zen\includes\templates\your_template_directory\common
if this file is not here then copy one from defalut template directory and create a common folder in your template diretory paste it in there and you can access this whole array there like this

$tempProduct=$_SESSION['tip'];
foreach($tempProduct as $product)
  {
  $proName=$product['productsName'];
  $proPriceEach=$product['productsPriceEach'];
  $proImg=$product['productsImage'];
  $proQty=$product['showFixedQuantityAmount'];
  $proAttribs=$product['attributes'];
  ?>
  <tr>
  		<td colspan="5"><?php echo $proName;?></td>
  </tr>

  <tr>
  	<td rowspan="2" id="balloonProImg">
	<?php 
	$src=htmlentities($proImg,ENT_NOQUOTES);
	$s = explode(" ", $src);
	$s =explode ("=",$s[1]);
	$img= $s[1];
	$pat = '/(^"+|"+$)/';
	$imgWOQ=preg_replace( $pat, '', $img );
	$imgWH = getimagesize($imgWOQ);
	$percent=0.10;//10%
	$width=round($imgWH[0]*$percent);
	$height=round($imgWH[1]*$percent);
	echo "<img src=\"$imgWOQ\" width=\"$width\" height=\"$height\"/>";
	?> 
    </td>
    <td>Qty</td>
    <td>Color</td>
    <td>Size</td>
    <td>Total</td>
  </tr>
  
  <tr>
    <td><?php echo $proQty;?></td>
	<?php 
    $count=count($proAttribs);
	for($i=1; $i<=$count; $i++)
		{
			$allAttribs=$proAttribs[$i];
			//print_r($indProduct);
			$productOption=$allAttribs[products_options_name];
			$productVal=$allAttribs[products_options_values_name];
			//echo $productVal;
			echo "<td >$productVal</td>";
		}
	?>
  <td><?php echo $proPriceEach; ?></td>
  </tr>
  <tr><td> </td></tr>
  <?php
  }
  ?>
  </table>

and this is my code of tooltip

<script type="text/javascript"> new Tip('bag',$('divText'), { title : 'Your Shopping Bag Has</br><strong><?php echo sizeof($_SESSION['cart']->get_products()); ?> </strong> Item(s)  <?php echo $currencies->format($_SESSION['cart']->show_total());?> ', //ajax: { url: 'includes/templates/template_default/sideboxes/tpl_shopping_cart.php', options: { onComplete: function(transport) {/*write your code*/} } }, style:'darkgrey', hideOn: { element: '.close', event: 'click'}, closeButton: true, hook: { target: 'topMiddle', tip: 'bottomRight' }, stem: 'topRight', offset: { x: -7, y: 135 } }); </script>

for this you will need to read
http://www.nickstakenburg.com/projects/prototip2/

now as you are adding products to $_SESSION array and able to view it in virtually any where, what about if any product is deleted form shoppingcart then if wont refresh the $_SESSION array so for this you need an other change
in
zen\includes\classes```php
after line no.553 after the if condition but in the remove fucntion
foreach ( $_SESSION['tip'] as $key => $value )
{
if ( in_array( $products_id, $value) )
{
unset( $_SESSION['tip'][$key] );
echo 'unseted//';
}
}


after this you will have a session arry $_SESSION['tip'] array which updates it self with all the changes.

ok guys this method works for me you can change it for you need
it might have any problem but non that i am aware of

hope this help any one out there

regards
salman sadiq
9 Jul 2008, 7:54 AM
#14
cybersavior avatar

cybersavior

New Zenner

Join Date:
Jul 2008
Posts:
1
Plugin Contributions:
0

Re: Showing cart items

for this you will need to read
http://www.nickstakenburg.com/projects/prototip2/

now as you are adding products to $_SESSION array and able to view it in virtually any where, what about if any product is deleted form shoppingcart then if wont refresh the $_SESSION array so for this you need an other change
in
zen\includes\classes
PHP Code:
after line no.553 after the if condition but in the remove fucntion
foreach ( $_SESSION['tip'] as $key => $value )
{
if ( in_array( $products_id, $value) )
{
unset( $_SESSION['tip'][$key] );
echo 'unseted//';
}
}

would like to do this on my site, tried following your instructions.... are you talking about the shopping_cart.php in classes folder?

also im new to zen, where would i be injecting the javascript code? im pretty sure the *.js goes in the templates/yourtemplate/jscript folder but the script you have... where does that go

if im just dumb you can tell me too.... along with the answer :wacko: