function SearchConfigurationInDataBase($variants, $productID) { $q = db_query('select itemID from ' . SHOPPING_CARTS_TABLE . ' where customerID=' . (int) regGetIdByLogin($_SESSION['log'])); while ($r = db_fetch_row($q)) { $q1 = db_query('select COUNT(*) from ' . SHOPPING_CART_ITEMS_TABLE . ' where productID=' . (int) $productID . ' AND itemID=' . (int) $r['itemID']); $r1 = db_fetch_row($q1); if ($r1[0] != 0) { $variants_from_db = GetConfigurationByItemId($r['itemID']); if (CompareConfiguration($variants, $variants_from_db)) { return $r['itemID']; } } } return -1; }
/** * search configuration in database * @param $variants * @param $productID * @return int */ function SearchConfigurationInDataBase($variants, $productID) { $sql = 'SELECT `itemID` FROM `?#SHOPPING_CARTS_TABLE` WHERE `customerID`=?'; $q = db_phquery($sql, regGetIdByLogin($_SESSION["log"])); while ($r = db_fetch_row($q)) { $sql1 = 'SELECT COUNT(`itemID`) FROM `?#SHOPPING_CART_ITEMS_TABLE` WHERE `productID`=? AND `itemID`=?'; $q1 = db_phquery($sql1, $productID, $r["itemID"]); $r1 = db_fetch_row($q1); if ($r1[0] != 0) { $variants_from_db = GetConfigurationByItemId($r["itemID"]); if (CompareConfiguration($variants, $variants_from_db)) { return $r["itemID"]; } } } return -1; }
function moveCartFromSession2DB() { if (isset($_SESSION["gids"]) && isset($_SESSION["log"])) { $customerID = regGetIdByLogin($_SESSION["log"]); $q = db_query("select itemID from " . SHOPPING_CARTS_TABLE . " where customerID=" . $customerID); $items = array(); while ($item = db_fetch_row($q)) { $items[] = $item["itemID"]; } //$i=0; foreach ($_SESSION["gids"] as $key => $productID) { if ($productID == 0) { continue; } // search product in current user's shopping cart content $itemID = null; for ($j = 0; $j < count($items); $j++) { $q = db_query("select count(*) from " . SHOPPING_CART_ITEMS_TABLE . " where productID=" . $productID . " AND " . " itemID=" . $items[$j]); $count = db_fetch_row($q); $count = $count[0]; if ($count != 0) { // compare configuration $configurationFromSession = $_SESSION["configurations"][$key]; $configurationFromDB = GetConfigurationByItemId($items[$j]); if (CompareConfiguration($configurationFromSession, $configurationFromDB)) { $itemID = $items[$j]; break; } $itemID = $items[$j]; } } if ($itemID == null) { // create new item db_query("insert into " . SHOPPING_CART_ITEMS_TABLE . " (productID) values('" . $productID . "')\n"); $itemID = db_insert_id(); // set content item foreach ($_SESSION["configurations"][$key] as $var) { db_query("insert into " . SHOPPING_CART_ITEMS_CONTENT_TABLE . " ( itemID, variantID ) " . " values( '" . $itemID . "', '" . $var . "' )\n"); } if ($_SESSION["sample"][$key]) { $quantity = 1; $sample = 1; } else { $quantity = $_SESSION["counts"][$key]; $sample = 0; } // insert item into cart db_query("insert " . SHOPPING_CARTS_TABLE . "(customerID, itemID, Quantity, sample)" . "values( '" . $customerID . "', '" . $itemID . "', '" . $quantity . "', '" . $sample . "' )\n"); } else { if (!$_SESSION["sample"][$key]) { db_query("update " . SHOPPING_CARTS_TABLE . " set Quantity=Quantity + " . $_SESSION["counts"][$key] . " " . " where customerID=" . $customerID . " and itemID=" . $itemID . "\n"); } } } unset($_SESSION["gids"]); unset($_SESSION["counts"]); unset($_SESSION["configurations"]); unset($_SESSION["sample"]); } }
function moveCartFromSession2DB() { //all products in shopping cart, which are in session vars, move to the database if (isset($_SESSION["gids"]) && isset($_SESSION["log"])) { $customerID = regGetIdByLogin($_SESSION["log"]); $q = db_query("select itemID from " . SHOPPING_CARTS_TABLE . " where customerID=" . (int) $customerID); $items = array(); while ($item = db_fetch_row($q)) { $items[] = (int) $item["itemID"]; } //$i=0; foreach ($_SESSION["gids"] as $key => $productID) { if ($productID == 0) { continue; } // search product in current user's shopping cart content $itemID = null; for ($j = 0; $j < count($items); $j++) { $q = db_query("select count(*) from " . SHOPPING_CART_ITEMS_TABLE . " where productID=" . (int) $productID . " AND itemID=" . (int) $items[$j]); $count = db_fetch_row($q); $count = $count[0]; if ($count != 0) { // compare configuration $configurationFromSession = $_SESSION["configurations"][$key]; $configurationFromDB = GetConfigurationByItemId($items[$j]); if (CompareConfiguration($configurationFromSession, $configurationFromDB)) { $itemID = $items[$j]; break; } } } if ($itemID == null) { // create new item db_query("insert into " . SHOPPING_CART_ITEMS_TABLE . " (productID) values(" . (int) $productID . ")"); $itemID = db_insert_id(); // set content item foreach ($_SESSION["configurations"][$key] as $vars) { db_query("insert into " . SHOPPING_CART_ITEMS_CONTENT_TABLE . " ( itemID, variantID ) " . " values( " . (int) $itemID . ", " . (int) $vars . " )"); } // insert item into cart db_query("insert " . SHOPPING_CARTS_TABLE . " (customerID, itemID, Quantity) values ( " . (int) $customerID . ", " . (int) $itemID . ", " . (int) $_SESSION["counts"][$key] . " )"); } else { db_query("update " . SHOPPING_CARTS_TABLE . " set Quantity=Quantity + " . (int) $_SESSION["counts"][$key] . " where customerID=" . (int) $customerID . " and itemID=" . (int) $itemID); } } unset($_SESSION["gids"]); unset($_SESSION["counts"]); unset($_SESSION["configurations"]); session_unregister("gids"); //calling session_unregister() is required since unset() may not work on some systems session_unregister("counts"); session_unregister("configurations"); } }