User Tools

Site Tools


tutorials:zencartmods:hideqty.html

Hiding inventory numbers

You can simplify your inventory display so that over a certain qty, the cart just says "In Stock"

In this example, we use 100 as the limit under which we display the quantity but of course you can change that pretty easily in the define to whatever you wish

New Files

Create a defines page, call it anything (we called it products_quantities_mods.php) and put it in /includes/extra_datafiles/

<?php
define(STOCK_SHOW_LIMIT, 100);
define(STOCK_OFFSET, 3);
define(STOCK_TEXT_IN_STOCK, 'IN STOCK');
define(STOCK_TEXT_QUANTITY_IN_STOCK, 'IN STOCK');
define(STOCK_TEXT_OUT_OF_STOCK, 'OUT OF STOCK');
?>

This should be the entire file.

NB: Make sure there isnt any white space before the '<?php' or after the '?>'. Any whitespace output there will cause php to send headers, which you don't want to do yet.

Change Settings

Make sure that the normal method for displaying products quantity is disabled.

Go to Admin>Catalog>Product Types>Products( General )>Edit Layout

and set Show Quantity in Stock to false. (Do this for Products (General), and any other types of products you use in the store)

This will remove the quantity display from everywhere on the site. This tutorial will cover adding it back into the individual products page and the products listing page. If you'd like to keep this feature enabled, please see the optional instructions at the bottom.

Show Quantity up to 100

Files to modify:

/includes/templates/YOUR_TEMPLATE/tpl_product_info_display.php
/includes/modules/product_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

Paste this new code into tpl_product_info_display.php anywhere you'd like – we recommend right below the price (line 75)

<div class="availability">
<?php
if($products_quantity > STOCK_SHOW_LIMIT)	
  echo STOCK_TEXT_IN_STOCK;
elseif($products_quantity > 0)	
  echo $products_quantity . ' ' . STOCK_TEXT_QUANTITY_IN_STOCK;
else	
  echo STOCK_TEXT_OUT_OF_STOCK;
?>      
</div>

in includes/modules/product_listing.php

find (lines 148-151)

case 'PRODUCT_LIST_QUANTITY':
        $lc_align = 'right';
        $lc_text = $listing->fields['products_quantity'];

and replace them with

case 'PRODUCT_LIST_QUANTITY':
        $lc_align = 'right';
	if($listing->fields['products_quantity'] > STOCK_SHOW_LIMIT)
          $lc_text = STOCK_TEXT_IN_STOCK;
	elseif($listing->fields['products_quantity'] > 0)
          $lc_text = $listing->fields['products_quantity'] . ' ' . STOCK_TEXT_QUANTITY_IN_STOCK;
        else
          $lc_text = STOCK_TEXT_OUT_OF_STOCK;

in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

find (line 59)

$display_products_quantity = TEXT_PRODUCTS_QUANTITY . $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

and replace with

          if ($products_all->fields['products_quantity'] > STOCK_SHOW_LIMIT)
            $display_products_quantity = STOCK_TEXT_IN_STOCK;
          elseif($products_all->fields['products_quantity'] > 0)
            $display_products_quantity = $products_all->fields['products_quantity'] . ' ' . STOCK_TEXT_IN_STOCK;
          else
            $display_products_quantity = STOCK_TEXT_OUT_OF_STOCK;
          $display_products_quantity .=	str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

Optional Stuff

If you would rather not set the "Show Products Quantity" option to false then you'll need to make the following mods as well to each of the following files:

Modified Files:
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_featured_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_new_listing.php

For the Stock Limit:

in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php

find (line59)

$display_products_quantity = TEXT_PRODUCTS_QUANTITY . $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

and replace with

          if ($products_all->fields['products_quantity'] > STOCK_SHOW_LIMIT)
            $display_products_quantity = STOCK_TEXT_IN_STOCK;
          elseif($products_all->fields['products_quantity'] > 0)
            $display_products_quantity = $products_all->fields['products_quantity'] . ' ' . STOCK_TEXT_IN_STOCK;
          else
            $display_products_quantity = STOCK_TEXT_OUT_OF_STOCK;
          $display_products_quantity .=	str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

The changes for tpl_modules_products_featured_listing.php and tpl_modules_products_new_listing.php are identical except that the variable $products_all should be replaced with $featured_products and $products_new respectively.

/home/ladyada/public_html/wiki/data/pages/tutorials/zencartmods/hideqty.html.txt · Last modified: 2016/01/28 18:05 (external edit)