Exemple #1
0
 /**
  * Returns a singular result from a mysql query
  * @param $strQuery string - mysql query
  * @return mixed - first record, first row
  */
 function getOne($strQuery)
 {
     $res = amDB::query($strQuery);
     if ($res && amDB::numRows($res)) {
         return mysql_result($res, 0, 0);
     }
     return false;
 }
 /**
  * Adds the selected attribute to the current product
  * @access public
  * @author Sam West aka Nimmit - osc@kangaroopartners.com
  * @author correction made by RusNN
  * @param $get $_GET
  * @return void
  */
 function addStockToProduct($get)
 {
     $inputok = true;
     // Work out how many option were sent
     while (list($v1, $v2) = each($get)) {
         if (preg_match("/^option(\\d+)\$/", $v1, $m1)) {
             if (is_numeric($v2) and $v2 == (int) $v2) {
                 $val_array[] = $m1[1] . "-" . $v2;
             } else {
                 $inputok = false;
             }
         }
     }
     if ($inputok) {
         $this->getAndPrepare('stockQuantity', $get, $stockQuantity);
         if (!empty($val_array)) {
             // Products has at least one assigned option or options combination, so set quantity for option combination and total options quantity for product itself
             sort($val_array, SORT_NUMERIC);
             $val = join(",", $val_array);
             $q = amDB::query("select products_stock_id as stock_id from " . TABLE_PRODUCTS_STOCK . " where products_id ='{$this->intPID}' and products_stock_attributes='" . $val . "' order by products_stock_attributes");
             if (amDB::numRows($q) > 0) {
                 $stock_item = amDB::fetchArray($q);
                 $stock_id = $stock_item['stock_id'];
                 if ($stockQuantity = intval($stockQuantity)) {
                     $data = array('products_stock_quantity' => (int) $stockQuantity);
                     // New value for option combination - updates DB
                     amDB::perform(TABLE_PRODUCTS_STOCK, $data, 'update', "products_stock_id={$stock_id}");
                 } else {
                     if (AM_DELETE_ZERO_STOCK) {
                         // If user inputs 0 (zero), delete such combination
                         amDB::query("delete from " . TABLE_PRODUCTS_STOCK . " where products_stock_id={$stock_id}");
                     } else {
                         // Set combination qty to 0
                         $data = array('products_stock_quantity' => '0');
                         // New value for option combination - updates DB
                         amDB::perform(TABLE_PRODUCTS_STOCK, $data, 'update', "products_stock_id={$stock_id}");
                     }
                 }
             } else {
                 // No such combination, insert new one
                 $data = array('products_id' => $this->intPID, 'products_stock_attributes' => $val, 'products_stock_quantity' => (int) $stockQuantity);
                 amDB::perform(TABLE_PRODUCTS_STOCK, $data);
             }
             $this->repairStock();
         } else {
             // No options available for the product, so sets the overall product quantity
             $data = array('products_quantity' => empty($stockQuantity) ? '0' : $stockQuantity);
             amDB::perform(TABLE_PRODUCTS, $data, 'update', "products_id='" . $this->intPID . "'");
             $this->checkProductStatus($stockQuantity);
         }
     }
 }