/** * override hook_add_to_cart * * @param string $nid * @param integer $qty * @param array $data * @return array */ 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 (db_affected_rows($result) == 1) { return array(array('success' => FALSE, 'message' => t('@product out of stock', array('@product' => $product->title)))); } }
private function checkKitToCart($node, $data) { if (!module_exists('uc_attribute')) { return true; } $isValid = true; foreach ($data['products'] as $productData) { $product = node_load($productData['nid']); uc_product_load($product); if ($this->hasRequiredAttributes($product)) { foreach ($product->attributes as $attribute) { if ($attribute->required == "1" && (!isset($productData['attributes'][$attribute->aid]) || empty($productData['attributes'][$attribute->aid]))) { drupal_set_message(t('You must choose an option for !attribute in !product', array('!attribute' => '<em>' . $attribute->name . '</em>', '!product' => '<strong>' . $product->title . '<strong>')), 'error'); $isValid = false; } } } } return $isValid; }
/** * override hook_add_to_cart * * @param string $nid * @param integer $qty * @param array $data * @return array */ function uc_stock_add_to_cart($nid, $qty, $data) { $product = node_load($nid); uc_product_load($product); if (isset($data['attributes'])) { foreach ($data['attributes'] as $aid => $value) { if (is_numeric($value)) { $combination[$aid] = $value; } } if (is_array($combination)) { 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)))); } }