Show quantity in cart on each product_info.php page
Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!
On the official osCommerce forum, Will asks;
Does anyone know how I could had on the product page (product_info.php), near the buy it now button, a line of text saying: You have XXXX units of this item currently in your cart.
I didn't really read the question so gave the advice to use the in_cart class for this. Wrong!
Will then went away and came up with some code to do this, which is like this:
Workable, but ugly and complicated. Here's my take on getting the same thing, coded to osCommerce conventions;
will bring you the number of products in the cart on the product info page. Use this with sprintf to show the text;
includes/languages/english/product_info.php
includes/languages/french/product_info.php
in product_info.php
Pretty easy!



Hey Gary,
It's Will here…
You're code is very good but for a reason, it does'nt work if I want to use it with AJAX.
Like on my site… http://www.khe opsinternational.ca/catalog/product_info.php?products_id=1150
Very great website BTW !
Will
Comment by Will — July 28, 2009 @ 8:12 am
Ho yeah…
and my first code and yours won't work with attribute…
Someone from the french osc forum helped me and this would work with attribute:
$superid = $product_info['products_id'];
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
$prid = tep_get_prid($products[$i]['id']);
if ($prid == $superid) {
$qtyencart = $products[$i]['quantity'];
echo"Vous avez $qtyencart unité de cet item dans votre panier actuellement.";
break;
}
}
Hope this can help someone!
Now I want to add this code also on the categorie page near each add to cart button..
this might be harder…
Bye
Comment by Will — July 28, 2009 @ 8:18 am
No…
echo $cart->get_quantity(tep_get_prid($product_info['products_id']));
would work (possibly) with attributes – haven't tested. Don't ever do more code than is necessary.
a product with attribute is like this: product_info.php?products_id=1{4}1{3}5
the function tep_get_prid strips out the options, to make it back to this: product_info.php?products_id=1
Comment by Gary — July 28, 2009 @ 8:24 am
Well just wanted to say that you're code work with ajax too. I was wrong!
Thank's for your help on the forum and on your great blog.
Will
Comment by Will — July 29, 2009 @ 5:40 am