How To: Show Stock Level For Each Item In Cart at Check Out

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 Level For Each Item In Cart at Check Out

Post by MegaFemaTron2 »

Cart Version: 6.1.1 Ultimate Edition

This is how to add inventory levels for each product in your customer's cart. I don't know PHP so I'm slowly learning by trial and error because I need implement some wholesaler code and have been unable to find a reliable programmer. So I am learning while I continue to look for one. Anyway, this is my latest accomplishment. :geek:

The goal is to get something like "CURRENT STOCK LEVEL: "stock number from database"" for each item in the cart, right under the product name link (you can put it anywhere you want but I put it there because it made sense to me. What was there before was %%GLOBALS_ProductAvailability%% which is what helped me figure all this out in the first place).

In /include/classes/class.quote.item.php FIND THIS:

Code: Select all

	/**
	 * Return the product availability string for this product. This is just
	 * a field configured for the product and shown during checkout.
	 *
	 * @return string Availability message.
	 */
	public function getAvailability()
	{
		$productData = $this->getProductData();
		if (!empty($productData['prodavailability'])) {
			return $productData['prodavailability'];
		}

		return '';
	}
And ADD THIS AFTER it:

Code: Select all

         /**
    * Return the product stock level string for this product. This is just
    * a field configured for the product and shown during checkout.
    *
    * @return string stock level message.
    */
   public function getStockl()
   {
      $productData = $this->getProductData();
      if (!empty($productData['prodcurrentinv'])) {
         return $productData['prodcurrentinv'];
      }

      return 'Out of Stock!';
   }
Then in /includes/display/CartContent.php FIND THIS:

Code: Select all

$GLOBALS['ProductAvailability'] = $item->getAvailability();
And ADD THIS AFTER it:

Code: Select all

$GLOBALS['ProductStockl'] = $item->getStockl();
Then in /templates/nameofyourtemplate/Snippets/CartItem.html FIND THIS:

Code: Select all

%%GLOBALS_ProductAvailability%%
And ADD THIS AFTER:

Code: Select all

<strong>CURRENT STOCK LEVEL: %%GLOBAL_ProductStockl%%</strong>
** If your Snippets folder is empty or doesn't have CartItem.html, you can get the file from the _Master/Snippets/ folder int the /templates/ directory. Copy the file to your template folder under Snippets.

You are all done! Now your shopping cart should show your stock levels for each item in the cart. I'll be working on getting this to work on the category product listing pages (where I really need it).
ISC 6.1.1 Ultimate Edition
Post Reply