6 replies [Last post]
stephan's picture
Offline
Joined: 10/03/2007
Juice: 19
Was this information Helpful?

Hi,

i successfully added the stock level to my product_list view. However, I'd also like to show the stock level directly on each products' page. Is there a way to do it?

Thanks,
Stephan

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Stock level on product detail page

You can modify your template directly to include this... you have to use the function uc_stock_level() and pass in the SKU I believe for this to work properly... from the template, you could try using $node->model.

linear's picture
Offline
Joined: 10/30/2008
Juice: 16
Re: Re: Stock level on product detail page

It'd be nice if the product description would accept ubercart tokens.
Then in the product description we could write
"There are [stock-level] items in stock."

This kind of functionality is already provided in
Administer -> Store Administration -> Configuration -> Stock Settings
where we see in the "Message text:" box,
"This message has been sent to let you know that the stock level for the model [stock-model] has reached [stock-level]. ... "

How do we do that (or make the template do that) for the product description?
Other comments appreciated.

(P.S. I'm very new to Drupal/Ubercart.)

72dpi's picture
Offline
Joined: 10/07/2007
Juice: 134
Re: Stock level on product detail page

Anyone have any luck with this one or done similar?

I really want to implement this, but not sure where to start. =(

snicers's picture
Offline
Uber DonorInternationalizationizer
Joined: 09/20/2007
Juice: 192
Re: Re: Stock level on product detail page

There is a pretty cool solution around. You need to put some code into your template.
Check http://www.ubercart.org/forum/support/4037/stock_level_product_page . It's working fine!

72dpi's picture
Offline
Joined: 10/07/2007
Juice: 134
Thanks Snicers, I had lost

Thanks Snicers,

I had lost track of that post.

I have tried, it works great, now just to find out which file outputs the sku, add to cart button etc, so i can add it inline.

Cheers!

davidw's picture
Offline
Joined: 05/27/2009
Juice: 95
Re: Stock level on product detail page

I am really stuck on how to add stock level to my product list pages.

I have successfully added the stock level to my product detail pages thanks to frost's post quoted below. (which works beautifully!)

I am using Ubercart for more or less a product inventory system, so it's important that I be able to show quantity of stock in a list view.

Can anybody steer me in the right direction before I lose my mind?

frost wrote:

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.