How To: Show Stock Levels On Category Product listing Pages
Posted: Fri Dec 02, 2011 9:48 pm
Cart Version: 6.1.1 Ultimate Edition
** This is for LIST view only ** - You could probably adapt it to grid view by adding the changes to: if ($display_mode == "Grid") instead of: if ($display_mode == "List"). And I think it uses a different snippet file as well. But I don't use the grid mode and don't have time to work out adding the stock levels in grid view.
Ok, here is how to show the stock level for each product when customers are viewing the list of products by category. I'm always shocked when I figure this stuff out. hahahaha
In /includes/display/CategoryContent.php FIND THIS:
ADD THIS BEFORE it:
Then FIND THIS:
And ADD THIS AFTER it:
The complete code should look like:
Then in /templates/yourtemplatename/Snippets/CategoryProductsItemsList.html FIND THIS:
ADD THIS AFTER it like so:
Of course you can add this last bit anywhere you want. I use the list mode (didn't do this for grid because I don't use it). I wanted the stock count underneath the price and quantity boxes on the right.
** If your Snippets folder is empty or doesn't have CategoryProductsItemsList.html, you can get the file from the _Master/Snippets/ folder int the /templates/ directory. Copy the file to your template folder under Snippets.
** This is for LIST view only ** - You could probably adapt it to grid view by adding the changes to: if ($display_mode == "Grid") instead of: if ($display_mode == "List"). And I think it uses a different snippet file as well. But I don't use the grid mode and don't have time to work out adding the stock levels in grid view.

Ok, here is how to show the stock level for each product when customers are viewing the list of products by category. I'm always shocked when I figure this stuff out. hahahaha
In /includes/display/CategoryContent.php FIND THIS:
Code: Select all
// get a small chunk of the product description
$desc = isc_substr(strip_tags($row['proddesc']), 0, 225);
Code: Select all
$inv = $row['prodcurrentinv'];
Code: Select all
$GLOBALS['ProductDescription'] = $desc;
Code: Select all
$GLOBALS['ProductStockCat'] = $inv;
Code: Select all
foreach($products as $row) {
$this->setProductGlobals($row);
// for list style
if ($display_mode == "List") {
$inv = $row['prodcurrentinv'];
// get a small chunk of the product description
$desc = isc_substr(strip_tags($row['proddesc']), 0, 225);
if (isc_strlen($row['proddesc']) > 225) {
// trim the description back to the last period or space so words aren't cut off
$period_pos = isc_strrpos($desc, ".");
$space_pos = isc_strrpos($desc, " ");
// find the character that we should trim back to. -1 on space pos for a space that follows a period, so we dont end up with 4 periods
if ($space_pos - 1 > $period_pos) {
$pos = $space_pos;
}
else {
$pos = $period_pos;
}
$desc = isc_substr($desc, 0, $pos);
$desc .= "...";
}
$GLOBALS['ProductDescription'] = $desc;
$GLOBALS['ProductStockCat'] = $inv;
Code: Select all
<span class="ProductRightCol">
<span class="ProductPrice">%%GLOBAL_ProductPrice%%</span>
<span class="ProductQty">
%%GLOBAL_AddToCartQty%% %%GLOBAL_InventoryList%%
</span>
Code: Select all
<br>
<br>
<span class="ProductPrice"><center>%%GLOBAL_ProductStockCat%%<br> Stock Level</center></span
** If your Snippets folder is empty or doesn't have CategoryProductsItemsList.html, you can get the file from the _Master/Snippets/ folder int the /templates/ directory. Copy the file to your template folder under Snippets.