How To: Show Stock Levels On Category Product listing Pages

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Post Reply
MegaFemaTron2
Confirmed
Confirmed
Posts: 84
Joined: Thu Oct 13, 2011 8:37 pm

How To: Show Stock Levels On Category Product listing Pages

Post by MegaFemaTron2 »

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:

Code: Select all

// get a small chunk of the product description
	$desc = isc_substr(strip_tags($row['proddesc']), 0, 225);
ADD THIS BEFORE it:

Code: Select all

 $inv = $row['prodcurrentinv']; 
Then FIND THIS:

Code: Select all

 $GLOBALS['ProductDescription'] = $desc;
And ADD THIS AFTER it:

Code: Select all

 $GLOBALS['ProductStockCat'] = $inv;
The complete code should look like:

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;
Then in /templates/yourtemplatename/Snippets/CategoryProductsItemsList.html FIND THIS:

Code: Select all

 <span class="ProductRightCol">
	<span class="ProductPrice">%%GLOBAL_ProductPrice%%</span>
	<span class="ProductQty">
	%%GLOBAL_AddToCartQty%% %%GLOBAL_InventoryList%%
	</span>
ADD THIS AFTER it like so:

Code: Select all

 <br>
	 <br>
	 <span class="ProductPrice"><center>%%GLOBAL_ProductStockCat%%<br> Stock Level</center></span
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.
Last edited by MegaFemaTron2 on Wed Jan 11, 2012 3:30 pm, edited 2 times in total.
ISC 6.1.1 Ultimate Edition
MegaFemaTron2
Confirmed
Confirmed
Posts: 84
Joined: Thu Oct 13, 2011 8:37 pm

Re: How To: Show Stock Levels On Category Product listing Pa

Post by MegaFemaTron2 »

Or you could use the following instead in /includes/display/CategoryContent.php:

Code: Select all

				if ($display_mode == "List") {
				        
				        if ($row['prodcurrentinv'] < 1) {
				        $stockout = "Out of stock";
				        $GLOBALS['ProductStockCat'] = '';
					$GLOBALS['ProductStockOutMessage'] = $stockout;
				        } 
				        else {
				        $inv = $row['prodcurrentinv'];
				        $GLOBALS['ProductStockCat'] = "$inv In Stock";
					$GLOBALS['ProductStockOutMessage'] = '';
				        }
And then in /templates/yourtemplatename/Snippets/CategoryProductsItemList.php use THIS:

Code: Select all

								<div class="ProductDetails">
									<span class="ProductRightCol">
										<span class="ProductPrice">%%GLOBAL_ProductPrice%%</span>
										<span class="ProductQty">
											%%GLOBAL_AddToCartQty%% %%GLOBAL_InventoryList%%
										</span>
										<br>
										<br>
										<span class="ProductPrice"><center>%%GLOBAL_ProductStockCat%% %%GLOBAL_ProductStockOutMessage%%</center></span>
									</span>
And
ISC 6.1.1 Ultimate Edition
Post Reply