Basic Out of Stock

Contrib type: 
Other
Status: 
Complete and working
Moderation: 
Awaiting moderation
Latest version: 
1.0

Downloads

Compatibility: 
Ubercart 2.x

**EDIT**
modules/uc_product/uc_product.module

**FIND**

if (module_exists('uc_cart')) {
  $node->content['add_to_cart'] = array('#value' => theme('uc_product_add_to_cart', $node, $teaser, $page),
    '#access' => $enabled['add_to_cart'],
    '#weight' => $weight['add_to_cart'],
  );
}

**CHANGE TO**

if (module_exists('uc_cart')) {
  $stock_level = db_result(db_query("SELECT stock FROM {uc_product_stock} WHERE nid = $node->nid"));
  if ((integer)$stock_level > 0) {
    $node->content['add_to_cart'] = array('#value' => theme('uc_product_add_to_cart', $node, $teaser, $page),
      '#access' => $enabled['add_to_cart'],
      '#weight' => $weight['add_to_cart'],
    );
  } else {
    $context['subject']['field'] = 'add_to_cart';
    $context['class'] = array('add_to_cart');
    $node->content['add_to_cart'] = array('#value' => '<strong>**Out of Stock</strong>', '#cell_attriubtes' => array('nowrap' => 'nowrap'));
  }
}

If someone wants to actually make this more than a basic hand patch.. or add it into core with some options.. that would be great.


TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3453
Re: Basic Out of Stock

I strongly suggest you do NOT use this approach. Aside from hacking core for a task that can be simply done through use of hooks, this approach has serious drawbacks. Instead, use something like http://www.ubercart.org/forum/support/4037/stock_level_product_page#comm... which doesn't involve hacking core. That comment also states some of the drawbacks, so at least you'll know what you're getting into when you use it. No way something as simplistic as either of these solutions belongs in core - they don't even meet the minimal thread-safe requirements for modifying stock levels, and do nothing to prevent selling more than you have in stock (or selling a unique item multiple times).

<tr>.
hakcenter's picture
Offline
Joined: 11/20/2009
Juice: 17
Re: Re: Basic Out of Stock

I've been using it on my shop for months on end.

If you want something better, by all means go ahead. I just got sick and tired of people buying things that I didn't have in my shop, and from the looks of the developers there is most likely never going to be any sort of control on that end.

Fundamentally having an option like 'stock' into products just necessitates some basic form of preventing people from purchasing things that don't exist (out of stock).

I would have hoped showing how a simple person, without even any knowledge of the core code of Ubercart could mod in basically 10 lines out of stock.. you'd think maybe it would make its way into the core code in a much better way than what I've shown.

calbasi's picture
Offline
Joined: 03/01/2009
Juice: 107
Module out_of_stock

Good job Smiling

Ps. There is some modules that try to do it, I've tested it and goes well (only a minor issue, for me) http://drupal.org/project/uc_out_of_stock But you job is another alternative Smiling (but I don't like a lot overwrite the core!)

---
calbasi.net
If you can not understand me, it's my poor English skills fault Sticking out tongue