Friday, July 17, 2009

Distinct "in cart" count in oscommerce

This is a tutorial on how to show a distinct count of the products added to the cart in oscommerce (my other post dealt with oscmax). The number generated here will correspond to the number of line items, disregarding quantities. For more information and an explanation of why you'd want this, see my previous post: Oscmax: how to show a distinct count of products in the cart.

Please note that I have not been able to test this code on a live server; rather, I've followed here the same adaptation that I had for oscmax.

*****

Open catalog/includes/classes/shopping_cart.php.

Search for "function numberOfItems" - should be around line 435.

A few lines under find:
return $total;
}

Just under add the following:

public function distinctNumberOfItems() {
$total = 0;

foreach ( $this->_contents as $product ) {
$total += 1;
}

return $total;
}

Save and upload.

Then wherever you want the count to appear, add the following code:

< ? php echo $osC_ShoppingCart->distinctnumberOfItems();

?>

Done and enjoy!

No comments:

Post a Comment