Display Shopping Cart Summary On Each PageLast Update: 21st July, 2005
Article ID: 56



Introduction

The shopping cart contents can be displayed on any page of the catalog by accessing certain methods/functions from the shopping cart class.

The following solution can be added to includes/header.php for it to be shown on all pages of the catalog.

Solution

The following HTML and PHP code can be used to display the number of items existing in the shopping cart:


<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td class="shoppingCartContents">
<?php
  
echo $cart->count_contents() . ' Items';

  if (
$cart->count_contents() > 0) {
    echo
'<br>Total: ' . $osC_Currencies->format($cart->show_total());
  }
?>
    </td>
  </tr>
</table>


The HTML and PHP code above uses a new shoppingCartContents stylesheet definition that has to be defined in the stylesheet.css file. This definition can be any name of choice.


The lbs (pounds) can also be displayed by using this php code:

<?php
  
echo $cart->count_contents() . ' Items';

  if (
$cart->count_contents() > 0) {
    echo
'<br>Total: ' . $osC_Currencies->format($cart->show_total()) . '<br>' . $cart->show_weight() . ($cart->show_weight() > 1 ? 'lbs' : 'lb');
  }
?>



This listing can run horizontally by using this code:

<?php
  
echo $cart->count_contents() . ' Items';

  if (
$cart->count_contents() > 0) {
    echo
' Total: ' . $osC_Currencies->format($cart->show_total()) . ' ' . $cart->show_weight() . ($cart->show_weight() > 1 ? 'lbs' : 'lb');
  }
?>

 

 

Trademark Policy | Copyright Policy | Sitemap

Copyright © 2000-2005 osCommerce. All rights reserved.