diff --git uc_modules_add_to_cart.php uc_modules_add_to_cart.php index f444241..bdac499 100644 --- uc_modules_add_to_cart.php +++ uc_modules_add_to_cart.php @@ -31,8 +31,23 @@ function uc_attribute_add_to_cart($nid, $qty, $data) { function uc_stock_add_to_cart($nid, $qty, $data) { $product = node_load($nid); uc_product_load($product) ; - $sql = "SELECT nid FROM {uc_product_stock} WHERE sku = '%s' AND nid = '%s' AND stock <= 0"; - $result = db_fetch_object(db_query($sql, $product->model, $nid)); + + if(isset($data['attributes'])) { + foreach ($data['attributes'] as $aid => $value) { + if (is_numeric($value)) { + $combination[$aid] = $value; + } + } + ksort($combination); + + $result = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d AND combination LIKE '%s'", $nid, serialize($combination)); + $model = db_result($result); + } else { + $model = $product->model; + } + + $sql = "SELECT nid FROM {uc_product_stock} WHERE sku = '%s' AND nid = '%s' AND active = 1 AND stock <= 0"; + $result = db_fetch_object(db_query($sql, $model, $nid)); if ( db_affected_rows($result) == 1 ) { return array(array('success' => FALSE, 'message' => t('@product out of stock', array('@product' => $product->title )))) ;