diff -bduNr /home/klavs/drupal6/uc_attribute_stock_filter-6.x-1.0-beta12/uc_attribute_stock_filter.module ./uc_attribute_stock_filter.module --- /home/klavs/drupal6/uc_attribute_stock_filter-6.x-1.0-beta12/uc_attribute_stock_filter.module 2009-04-06 02:32:03.000000000 +0200 +++ ./uc_attribute_stock_filter.module 2010-03-02 11:43:14.000000000 +0100 @@ -63,16 +63,13 @@ // Does the product have attributes? $product_attributes = db_fetch_object( db_query("SELECT COUNT(nid) as count FROM {uc_product_adjustments} WHERE nid = %d", $form['nid']['#value'])); - if ($product_attributes->count < 1) { - // No attributes - $stock = db_fetch_object( db_query("SELECT s.stock as count FROM {uc_product_stock} s WHERE s.nid = %d", $form['nid']['#value'])); + $stock = db_fetch_object( db_query("SELECT s.stock as count, s.active FROM {uc_product_stock} s WHERE s.nid = %d", $form['nid']['#value'])); } else { - $stock = db_fetch_object( db_query("SELECT COUNT(s.stock) AS count FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1 AND stock > 0", $form['nid']['#value'])); + $stock = db_fetch_object( db_query("SELECT COUNT(s.stock) AS count, s.active FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1 AND stock > 0 group by s.stock", $form['nid']['#value'])); } - - if ($stock->count < 1) { + if ($stock->count < 1 && $stock->active) { // We're all out, kill the 'Add to cart' submit button and disable any attribute select boxes $form['submit']['#attributes']['disabled'] = 'disabled'; $form['submit']['#value'] = t('Out of stock'); @@ -85,13 +82,13 @@ } } else if ($product_attributes->count > 0) { // The product has at least one attribute - $result = db_query("SELECT a.combination AS combination, s.stock AS stock FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1", arg(1)); + $result = db_query("SELECT a.combination AS combination, s.stock AS stock, s.active FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model", $form['nid']['#value']); // This builds an array containing the available options $available = array(); while ($data = db_fetch_object($result)) { $combo = unserialize($data->combination); - if ($data->stock) { // Stock is available + if ($data->stock || !$data->active) { // Stock is available or stock tracking is NOT active $available = array_merge($available, array_values($combo)); // Merge value into array } } diff -bduNr /home/klavs/drupal6/uc_attribute_stock_filter-6.x-1.0-beta12/uc_attribute_stock_filter.module_1.patch ./uc_attribute_stock_filter.module_1.patch --- /home/klavs/drupal6/uc_attribute_stock_filter-6.x-1.0-beta12/uc_attribute_stock_filter.module_1.patch 1970-01-01 01:00:00.000000000 +0100 +++ ./uc_attribute_stock_filter.module_1.patch 2009-08-02 17:23:56.000000000 +0200 @@ -0,0 +1,125 @@ +Index: uc_attribute_stock_filter.module +=================================================================== +RCS file: /cvs/drupal-contrib/contributions/modules/uc_attribute_stock_filter/uc_attribute_stock_filter.module,v +retrieving revision 1.12 +diff -u -p -r1.12 uc_attribute_stock_filter.module +--- uc_attribute_stock_filter.module 5 Apr 2009 22:58:25 -0000 1.12 ++++ uc_attribute_stock_filter.module 2 Aug 2009 15:16:37 -0000 +@@ -1,5 +1,5 @@ + nid)); ++ static $available = array(); + +- // Only proceed if we have more than one attribute (otherwise we do the filtering with hook_form_alter()) +- if ($attrib->count > 1) { +- // Grab serialized options and stock levels +- $result = db_query("SELECT a.combination AS combination, s.stock AS stock FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1", $node->nid); +- +- // This builds an array where each option is a key containing its available combinations as elements +- $available = array(); +- while ($data = db_fetch_object($result)) { +- $combo = unserialize($data->combination); +- if ($data->stock > 0) { // Stock is available +- foreach ($combo as $key => $option) { // Grab possible combinations +- foreach ($combo as $avail_key => $avail_opt) { +- if ($avail_key != $key) { +- $available[$option][] = $avail_opt; +- } ++ if (($op == 'view') || ++ (($op == 'load') && (preg_match('%^/catalog/%', request_uri())) && ++ variable_get('uc_catalog_grid_display_attributes', TRUE))) { ++ ++ // Get attribute count for this product ++ $attrib = db_fetch_object(db_query("SELECT COUNT(aid) AS count FROM {uc_product_attributes} WHERE nid = %d", $node->nid)); ++ ++ // Only proceed if we have more than one attribute (otherwise we do the filtering with hook_form_alter()) ++ if ($attrib->count > 1) { ++ // Grab serialized options and stock levels ++ $result = db_query("SELECT a.combination AS combination, s.stock AS stock FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1", $node->nid); ++ ++ // This builds an array where each option is a key containing its available combinations as elements ++ while ($data = db_fetch_object($result)) { ++ $combo = unserialize($data->combination); ++ if ($data->stock > 0) { // Stock is available ++ foreach ($combo as $key => $option) { // Grab possible combinations ++ foreach ($combo as $avail_key => $avail_opt) { ++ if ($avail_key != $key) { ++ $available[$node->nid][$option][] = $avail_opt; + } + } + } + } +- if (!empty($available)) { // If there are no stock levels at all, we assume stocks aren't used and skip filtering. ++ } ++ if (!empty($available)) { // If there are no stock levels at all, we assume stocks aren't used and skip filtering. + +- // Encode the array as JSON and add the JavaScript +- $js_array = "var uc_asf_AvailableOptions = ". json_encode($available); +- drupal_add_js($js_array, 'inline'); +- drupal_add_js(drupal_get_path('module', 'uc_attribute_stock_filter') .'/uc_attribute_stock_filter.js', 'module'); +- } ++ // Encode the array as JSON and add the JavaScript ++ $js_array = "var uc_asf_AvailableOptions = ". json_encode($available); ++ drupal_add_js($js_array, 'inline'); ++ drupal_add_js(drupal_get_path('module', 'uc_attribute_stock_filter') .'/uc_attribute_stock_filter.js', 'module'); + } +- break; ++ } + } + } + +@@ -59,20 +61,18 @@ function uc_attribute_stock_filter_form_ + + if (ereg('^uc_product_add_to_cart_form_', $form_id)) { + +- $stock = db_fetch_object( db_query("SELECT COUNT(s.stock) AS count FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1 AND stock > 0", $form['nid']['#value'])); +- + // Does the product have attributes? + $product_attributes = db_fetch_object( db_query("SELECT COUNT(nid) as count FROM {uc_product_adjustments} WHERE nid = %d", $form['nid']['#value'])); + + if ($product_attributes->count < 1) { + // No attributes +- $stock = db_fetch_object( db_query("SELECT s.stock as count FROM {uc_product_stock} s WHERE s.nid = %d", $form['nid']['#value'])); ++ $stock = db_fetch_object( db_query("SELECT s.stock AS count, s.active AS active FROM {uc_product_stock} s WHERE s.nid = %d", $form['nid']['#value'])); + } + else { +- $stock = db_fetch_object( db_query("SELECT COUNT(s.stock) AS count FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1 AND stock > 0", $form['nid']['#value'])); ++ $stock = db_fetch_object( db_query("SELECT COUNT(s.stock) AS count, 1 AS active FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1 AND stock > 0", $form['nid']['#value'])); + } + +- if ($stock->count < 0) { ++ if ($stock->active && $stock->count < 1) { + // We're all out, kill the 'Add to cart' submit button and disable any attribute select boxes + $form['submit']['#attributes']['disabled'] = 'disabled'; + $form['submit']['#value'] = t('Out of stock'); +@@ -84,8 +84,8 @@ function uc_attribute_stock_filter_form_ + } + } + } +- else if ($product_attributes->count > 0) { // The product has at least one attribute +- $result = db_query("SELECT a.combination AS combination, s.stock AS stock FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1", arg(1)); ++ else if ($stock->active && $product_attributes->count > 0) { // The product has at least one attribute ++ $result = db_query("SELECT a.combination AS combination, s.stock AS stock FROM {uc_product_adjustments} a, {uc_product_stock} s WHERE a.nid = %d AND s.sku = a.model AND s.active = 1", $form['nid']['#value']); + + // This builds an array containing the available options + $available = array(); +@@ -110,4 +110,4 @@ function uc_attribute_stock_filter_form_ + } + + } +-} +\ No newline at end of file ++}