Page 1 of 1

[MOD] Display stock quantity in Shopping Cart page

Posted: Wed Jan 13, 2010 7:08 am
by datacon
Hi all,

I have spend all day yesterday trying to display the stock quantity for each item in the Shopping cart page (basket).

Basically, instead of only the *** showing when a customer wants to order more than the store has in stock, I want to show *** and the number of stock that is available. I will then allow the customers to order even if the stock is not there, but the customer will know how many can ship straight away, and how many remaining will ship when stock comes in (up to 2 weeks).

So basically I am trying to put some code in the Cart.tpl page (catalog/view/theme/default/template/checkout/ in this section that will show the current stock quantity for that product (line by line), and then show how many will be on back-order.

Current:

Code: Select all

   <?php if (!$product['stock']) { ?>
            <span style="color: #FF0000; font-weight: bold;">***</span> 
            <?php } ?>
Desired (something like this):

Code: Select all

   <?php if (!$product['stock']) { ?>
            <span style="color: #FF0000; font-weight: bold;">***</span>(<?php echo $product['stock']; ?> in stock, <?php $remainder = $product['stock'] - $product['quantity']; echo $remainder; ; ?> will be on back-order and delivered within 2 weeks)<?php } ?>
$product['stock'] outputs exactly NOTHING, although i know something is working because the if statement is actively checking if the product is out of stock (<?php if (!$product['stock']) { ?>).

I have searched all threads on this forum, and tried various methods, most of which are made for the category/product pages, and dont work on the cart page. I also tried this method, but is not working for 1.3.4 anyway http://www.aleixcortadellas.com/main/2009/09/09/742/

Any help would be greatly appreciated. Thanks in advance!

OC Version: 1.3.4

Re: Display stock quantity in Shopping Cart page

Posted: Wed Jan 13, 2010 8:34 am
by Xsecrets
well I'll get back to this thread in a bit to see if I can come up with something if noone else has I can tell you that $product['stock'] outputing exactly NOTHING is exactly correct as if(!$product['stock']) will only activate if $product['stock'] is either not set or completely empty.

Re: Display stock quantity in Shopping Cart page

Posted: Wed Jan 13, 2010 9:35 am
by datacon
Thanks for your response Xsecrets. Looking forward to crack this, still trying new things, but am only a PHP novice :-\

If you come up with something, would greatly help me! Thanks

Re: Display stock quantity in Shopping Cart page

Posted: Wed Jan 13, 2010 1:18 pm
by Xsecrets
yeah I looked at it for a minute or two, but it looks like the qty will have to be pulled all the way from the system/library/cart.php and I didn't really have time to go through it all.

Re: Display stock quantity in Shopping Cart page

Posted: Fri Jan 15, 2010 9:10 am
by datacon
Xsecrets has helped me out on this one - thanks! Any one interested in the code to make this work can contact him via PM, or myself.

Re: Display stock quantity in Shopping Cart page

Posted: Fri Jan 15, 2010 9:34 am
by Qphoria
If I may:

1. EDIT: catalog/view/theme/YOURTHEME/template/checkout/cart.tpl

2. FIND:

Code: Select all

<?php if (!$product['stock']) { ?>
<span style="color: #FF0000; font-weight: bold;">***</span>
<?php } ?>
3. REPLACE WITH:

Code: Select all

 (<?php echo $product['stock']; ?>)
4. EDIT: system/library/cart.php

5. FIND:

Code: Select all

if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) {
	$stock = FALSE;
}
6. REPLACE WITH:

Code: Select all

$stock = $product_query->row['quantity'];

Re: Display stock quantity in Shopping Cart page

Posted: Tue Jan 19, 2010 10:58 am
by datacon
Thanks Q!!

Re: Display stock quantity in Shopping Cart page

Posted: Tue Jan 19, 2010 2:34 pm
by i2Paq
As this is a mod now I will move this topic.

Re: [MOD] Display stock quantity in Shopping Cart page

Posted: Wed Nov 16, 2011 9:31 am
by pxdva
Is there a way to modify this mod so that it works with 1.5.1.3?

Re: [MOD] Display stock quantity in Shopping Cart page

Posted: Tue Feb 14, 2012 6:04 am
by scpost
Just tested Qphoria code with 1.5.1.3 and it works!!!!!

I changed it a bit.... I returned a variable in the array (located right below the if (!$product_query->row['quantity').... to the controller and from the controller added this same var so it is returned to he template.. Now I display how many items are in stock)

Bottom line code works on 1.5.1.3, thanks Qphoria

Re: Display stock quantity in Shopping Cart page

Posted: Sat Mar 24, 2012 9:20 pm
by dimko
Qphoria wrote:If I may:

1. EDIT: catalog/view/theme/YOURTHEME/template/checkout/cart.tpl

2. FIND:

Code: Select all

<?php if (!$product['stock']) { ?>
<span style="color: #FF0000; font-weight: bold;">***</span>
<?php } ?>
3. REPLACE WITH:

Code: Select all

 (<?php echo $product['stock']; ?>)
4. EDIT: system/library/cart.php

5. FIND:

Code: Select all

if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) {
	$stock = FALSE;
}
6. REPLACE WITH:

Code: Select all

$stock = $product_query->row['quantity'];
Very nice, thanks Q ;)

I tried something like this:

Code: Select all

<?php if ($product['stock'] <= 0) echo $product['stock_status']; ?>
but no luck, it gives me error:

Code: Select all

Notice: Undefined index: stock_status in ...\catalog\view\theme\default\template\checkout\cart.tpl on line 58
Any quick help, how to implement the "stock_status" variable into the .php file?

Thanks in advance.