Post by datacon » Wed Jan 13, 2010 7:08 am

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

New member

Posts

Joined
Tue Nov 17, 2009 11:10 am

Post by Xsecrets » Wed Jan 13, 2010 8:34 am

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.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by datacon » Wed Jan 13, 2010 9:35 am

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

New member

Posts

Joined
Tue Nov 17, 2009 11:10 am

Post by Xsecrets » Wed Jan 13, 2010 1:18 pm

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.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by datacon » Fri Jan 15, 2010 9:10 am

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.

New member

Posts

Joined
Tue Nov 17, 2009 11:10 am

Post by Qphoria » Fri Jan 15, 2010 9:34 am

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'];

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by datacon » Tue Jan 19, 2010 10:58 am

Thanks Q!!

New member

Posts

Joined
Tue Nov 17, 2009 11:10 am

Post by i2Paq » Tue Jan 19, 2010 2:34 pm

As this is a mod now I will move this topic.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by pxdva » Wed Nov 16, 2011 9:31 am

Is there a way to modify this mod so that it works with 1.5.1.3?

Newbie

Posts

Joined
Thu Aug 04, 2011 6:20 am

Post by scpost » Tue Feb 14, 2012 6:04 am

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

New member

Posts

Joined
Thu Nov 10, 2011 12:51 am

Post by dimko » Sat Mar 24, 2012 9:20 pm

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.

Using OpenCart v1.5.1.3


Active Member

Posts

Joined
Sun Sep 25, 2011 2:10 am
Who is online

Users browsing this forum: No registered users and 10 guests