$nid, ':combination' => serialize($attributes)))->fetchField(); } // Product without attributes else { // Fetch the SKU from {uc_products} $sku = db_query("SELECT model FROM {uc_products} WHERE nid = :nid", array(':nid' => $nid))->fetchField(); } // Update qty from cart if ($form_state['clicked_button']['#name'] == 'update-cart') { $qty = $element['#value']; } // Add to cart from product else { // Fetch the qty in cart from {uc_cart_products} $qty_cart = db_query("SELECT qty FROM {uc_cart_products} WHERE nid = :nid", array(':nid' => $nid))->fetchField(); // Add qty of cart to the qty $qty = $qty_cart + $element['#value']; } // Verify stock level $stock_level = _uc_stock_validate_level($sku, $qty, $form['#form_id']); if ($stock_level !== TRUE) { form_error($element, $stock_level); } } /** * Validate stock level of a specific product. */ function _uc_stock_validate_level($sku = NULL, $qty = 1, $form_id = NULL) { // Get stock level of the product's SKU. $stock_level = uc_stock_level($sku); // If no stock level is set, we can skip further validation. if ($stock_level === FALSE) { return TRUE; } if ($stock_level <= 0) { //return t('This product is currently not available in stock with your selected options.'); preg_match_all('!\d+!', $form_id, $matches); $prod_id = $matches[0][0]; $date_of_expiry = time() +7200; setcookie("pds[" . $prod_id . "]", "ano", $date_of_expiry, "/", ".nasastopa.sk"); return TRUE; } // Check if selected quantity exceeds available product quantity. else if ($stock_level < $qty) { if ($stock_level == 1) { $str = t('Insufficient stock level. Only one product left.'); } else { $str = t('Insufficient stock level. Only !number products left.', array('!number' => $stock_level)); } $correct_qty = ""; // If the user add to cart from the product, text "correct selected qty" is not necesary if(strpos($form_id, 'uc_product_add_to_cart_form') === false){ $correct_qty = t('Please correct the selected quantity.'); $cart_product_index = $element['#parents'][1]; //AKO ZISKAT $NID? $product = $form_state['values']['items'][$cart_product_index]; //AKO ZISKAT $NID? $nid = $product['nid']; //AKO ZISKAT $NID? $date_of_expiry = time() +7200; setcookie("pds[" . $nid . "]", "ano", $date_of_expiry, "/", ".nasastopa.sk"); } //return $str.' '.$correct_qty; preg_match_all('!\d+!', $form_id, $matches); $prod_id = $matches[0][0]; $date_of_expiry = time() +7200; setcookie("pds[" . $prod_id . "]", "ano", $date_of_expiry, "/", ".nasastopa.sk"); return TRUE; } preg_match_all('!\d+!', $form_id, $matches); $prod_id = $matches[0][0]; $date_of_expiry = time() -7200; setcookie("pds[" . $prod_id . "]", "ano", $date_of_expiry, "/", ".nasastopa.sk"); return TRUE; }