Latest Articles
So far this was never an issue, there were problems with uploading modules via the installer because of the ftp connection but you could allways install ocmods without any issue. However, some .. Read More
People had this issue so many times I thought I would write a bit about it. The  types of issues with opencart's 2.x modification system that I identified so far are: 1. Old Vqmod .. Read More
This small tutorial will show you how to manually add custom links to the default top menu in opencart. If you dont want to go trough all the hustle and would like to be able to completly customize.. Read More
To enable seo urls in opencart navigate in admin to system > settings , edit the store and on the server tab of the store settings you will find "Use SEO urls", set it to yes. So far e.. Read More
All Articles

Display stock in opencart product listing

If you want to display the stock or stock status(like on product page) on the product linsting (category, search) here is how you do it.

Edit the file catalog/controller/product/category.php
Find the code:

if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}

below it add:

if ($result['quantity'] <= 0) {
$rstock = $result['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$rstock = "Stoc: " . $result['quantity'];
} else {
$rstock = "In stoc";
}

Then, after the code:


'thumb' => $image,

add:

'stoc' => $rstock,

Edit the file catalog/view/theme/yourtheme/template/product/category.tpl

after:

<div class="cart">

add

<?php echo $product['stoc']; ?><br />

And now the stock will appear for products in category page. You can do the same for search (the files would be search.php and search.tpl - in the same folders as the category)

Posted by Flo

22 Comments To "Display stock in opencart product listing"

mladen On 12 Dec 2013
Hi Flo Can you tell me how to hide (remove at all) stock status on product page if stock = 0 I,ll try this but doesnt work: <?php if ($stock > 0) { ?> <span><?php echo $text_stock; ?></span> <?php echo $stock; ?> <?php } ?> Thanx Reply to this comment
Flo On 14 Nov 2013
If you have another theme active then the default one, yet you made the modifications in the default one, than that is the reason its not showing up, make the modification in the custom theme. Reply to this comment
Freddie On 14 Nov 2013
I just followed this exactly, except I chose the default theme instead of my own, and nothing has changed... help? Reply to this comment
Ruchika On 15 Oct 2013
HI $result['quantity']; is always giving null in my case .I can see the caption on category page as "in Stoc" but Quamtity is not shown. Can you please help. Website:mypustak.com Reply me on a.ruchikakumari@gmail.com Reply to this comment
Solver On 01 Jul 2013
Hi, That worked well for all pages. Do you know how to sort product list? So I would see first products what are available than the one witch are sold. Reply to this comment
Rajesh On 22 Mar 2013
i tried this but its showing error as below "Parse error: syntax error, unexpected ':' in /home/tariffs/public_html/lights_pro/vqmod/vqcache/vq2-catalog_controller_product_category.php on line 191" please help me to fix it... Thanks Reply to this comment
Flo On 03 Dec 2012
Make the changes to featured.php first and then in featured.tpl. Reply to this comment
Handre On 03 Dec 2012
Hi Flo Thanks for the quick response. I have tried the VQMod but have customized my featured.tpl file quote heavily and havent been able to get it working.I need 2 different layouts and that is why I am using the featured.tpl module. How would I use your code above for the featured.tpl? At the moment it just gives me an error. Many thanks Reply to this comment
Flo On 16 Nov 2012
There is a controller: catalog/controller/module/featured.php. But you should better use the product display settings vqmod, as its easyer. Reply to this comment
Handre On 16 Nov 2012
Thanks Got it working but would like to know how could you accomplish this for the featured module? As there is no controller file for this? Reply to this comment

Write a comment

Your Name:


Enter the code in the box below:

Your Comment:
Note: HTML is not translated!