Display stock in opencart product listing

Posted by Flo on 18 Feb 2012

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:

<div class="code">
	<p>
		<br />
		&#39;thumb&#39; =&gt; $image,<br />
		<br /></div>
		add:<br />
		<br />	<div class="code">
		&#39;stoc&#39; =&gt; $rstock,<br />
		<br /></div>
		Edit the file catalog/view/theme/yourtheme/template/product/category.tpl<br />
		<br />
		after:</p>


<div class="code">
	<p>
		&lt;div class=&quot;cart&quot;&gt;<br />
		<br /></div>
		add<br />
		<br />	<div class="code">
		&lt;?php echo $product[&#39;stoc&#39;]; ?&gt;&lt;br /&gt;<br />
		<br /></div>
		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)</p>