one simple approach
Stock level on catalog page (28 replies) Mon, 03/31/2008 - 15:11
- Re: Stock level on catalog page (01/26/2010 - 23:31)
- Re: Stock level on catalog page (08/07/2009 - 22:08)
- Re: Re: Stock level on catalog page (08/23/2009 - 20:25)
- Re: Stock level on catalog page (04/02/2008 - 11:30)
- Theme snippet for stocklevel display on product pages (04/09/2008 - 02:25)
- Re: Theme snippet for stocklevel display on product pages (12/02/2009 - 20:10)
- Re: Re: Theme snippet for stocklevel display on product pages (12/04/2009 - 03:19)
- doesn't like line 3 (11/20/2009 - 16:15)
- Display order (12/04/2008 - 08:28)
- Re: Display order (04/08/2009 - 06:19)
- Re: Theme snippet for stocklevel display on product pages (05/26/2008 - 07:48)
- Re: Re: Theme snippet for stocklevel display on product pages (05/28/2008 - 13:46)
- Stock Level (08/22/2008 - 01:22)
- one simple approach (09/03/2008 - 19:05)
- frost wrote: Here's a simple (11/20/2009 - 16:18)
- Re: one simple approach (10/28/2009 - 14:19)
- Re: one simple approach (12/02/2008 - 16:48)
- Does it work for 6.14? (12/25/2009 - 11:22)
- Re: Re: one simple approach (11/03/2009 - 17:20)
- Added, not working (07/26/2009 - 16:10)
- Re: Added, not working (08/06/2009 - 13:17)
- It works nice except... When (06/19/2009 - 13:05)
- one simple approach (09/03/2008 - 19:05)
- Stock Level (08/22/2008 - 01:22)
- Re: Re: Theme snippet for stocklevel display on product pages (05/28/2008 - 13:46)
- Sweet keesje76, is that (04/10/2008 - 07:25)
- Re: Theme snippet for stocklevel display on product pages (04/10/2008 - 03:49)
- Re: Re: Theme snippet for stocklevel display on product pages (05/28/2008 - 13:43)
- Re: Theme snippet for stocklevel display on product pages (12/02/2009 - 20:10)
- Theme snippet for stocklevel display on product pages (04/09/2008 - 02:25)
- Re: Stock level on catalog page (04/02/2008 - 01:41)
- Re: Re: Stock level on catalog page (04/02/2008 - 08:33)
- I'm also interested... (04/01/2008 - 13:21)

Here's a simple way to display stock level for nodes, and also to remove the "add to cart" button if the stock is zero.
Add the following to the template.php file in your sites/all/themes/YOUR_THEME_NAME directory, changing the function name according to your theme's name:
function YOUR_THEME_NAME_uc_product_add_to_cart( $node ) {$stocklevel = uc_stock_level($node->model);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel == 0) {
return( '<div class="out_of_stock">' . t('Sorry, this item is out of stock') . '</div>' );
} else {
return( '<div class="stock_level">' . t('Number available: ') . $stocklevel . '</div>' ) . theme_uc_product_add_to_cart($node);
}
} else {
// Stock tracking is not being used for this product, just show the add to cart button as normal
return theme_uc_product_add_to_cart($node);
}
}
Note that there are some obvious limitations to this:
1. It doesn't stop someone adding a quantity to their cart that is greater than the stock available
2. It doesn't update in real time so you may see the "add to cart" button but there may be no stock available by the time you click it
3. Stock is normally updated when an item is purchased, but this code tests at "add to cart" time
4. It is unlikely to work with product attributes. I don't use attributes, so didn't test it, but from what I understand about them, I think this approach is too simplistic.