/** * @param int $orderID * @param array $shipping_info - ('countryID','zoneID', 'zip') * @param array $billing_info - ('countryID','zoneID', 'zip') */ function saveToOrderedCarts($orderID, $shipping_info, $billing_info, $calculate_tax = true) { $sql = "DELETE FROM ?#ORDERED_CARTS_TABLE WHERE orderID=?"; db_phquery($sql, $orderID); $r_aItem = $this->Items->getChildNodes('item'); $tc = count($r_aItem); for ($i = 0; $i < $tc; $i++) { $aItem =& $r_aItem[$i]; /* @var $aItem xmlNodeX */ $aProduct =& $aItem->getFirstChildByName('product'); $productID = $aProduct->attribute('id'); db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)', $productID); $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); //if(strpos($aItem->attribute('id'), '_') !== false){ // db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)',$productID); // $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ db_phquery('INSERT ?#SHOPPING_CART_ITEMS_CONTENT_TABLE (itemID, variantID) VALUES(?,?)', $aItem->attribute('id'), $aVariant->attribute('id')); } //} $dbq = ' SELECT ' . LanguagesManager::sql_prepareField('name') . ' AS name, product_code, categoryID FROM ?#PRODUCTS_TABLE WHERE productID=? '; $q_product = db_phquery($dbq, $productID); $product = db_fetch_row($q_product); $productComplexName = ''; $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); $variants = array(); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ $variants[] = $aVariant->attribute('id'); } $options = GetStrOptions($variants); if ($options != "") { $productComplexName = $product["name"] . " (" . $options . ")"; } else { $productComplexName = $product["name"]; } if ($product["product_code"]) { $productComplexName = "[" . $product["product_code"] . "] " . $productComplexName; } $price = GetPriceProductWithOption($variants, $productID); if ($aItem->getChildData('sample')) { $productComplexName .= " [SAMPLE]"; $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $productID); $sample_price = db_fetch_assoc($q_sample_price); $price = $sample_price["sample_price"]; $quantity = 1; } else { $quantity = $aItem->getChildData('quantity'); } $tax = $calculate_tax ? taxCalculateTax2($productID, $shipping_info, $billing_info) : 0; $dbq = ' INSERT ?#ORDERED_CARTS_TABLE (itemID, orderID, name, Price, Quantity, tax ) VALUES (?, ?, ?, ?, ?, ?) '; db_phquery($dbq, $aItem->attribute('id'), $orderID, $productComplexName, $price, $quantity, $tax); $q = db_phquery('SELECT statusID FROM ?#ORDERS_TABLE WHERE orderID=?', $orderID); $order = db_fetch_row($q); if ($order["statusID"] != ostGetCanceledStatusId() && CONF_CHECKSTOCK) { $dbq = ' UPDATE ?#PRODUCTS_TABLE SET in_stock=in_stock-' . xEscapeSQLstring($quantity) . ' WHERE productID=? '; db_phquery($dbq, $productID); } } }
function GetStrOptions($variants) { static $res_cache = array(); $variants = array_map('intval', $variants); $dbq = 'SELECT ' . LanguagesManager::sql_prepareField('option_value', true) . ',variantID FROM ?#PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE WHERE variantID IN(?@)'; $is_cached = true; $non_cached_variants = array(); foreach ($variants as $variantID) { if (!isset($res_cache[$variantID])) { $non_cached_variants[] = $variantID; } } if (count($non_cached_variants)) { if ($q = db_phquery($dbq, $non_cached_variants)) { while ($r = db_fetch_row($q)) { if ($r['option_value']) { $res_cache[$r['variantID']] = $r['option_value']; } } } } $result = array(); foreach ($variants as $variantID) { $result[] = $res_cache[$variantID]; } if (count($result)) { $res_str = ''; foreach ($result as $value) { if ($value != '') { if ($res_str == '') { $res_str .= $value; } else { $res_str .= ', ' . $value; } } } return $res_str; } else { return ""; } }
$row = db_fetch_row($q); if ($row) { if (!file_exists(DIR_PRODUCTS_PICTURES . "/" . $row[3])) { $row[3] = ""; } $smarty->assign("selected_category", $row); } //calculate a path to the category $smarty->assign("product_category_path", catCalculatePathToCategory($categoryID)); //reviews number $k = db_phquery_fetch(DBRFETCH_FIRST, "SELECT count(*) FROM ?#DISCUSSIONS_TABLE WHERE productID=?", $productID); //extra parameters $extra = GetExtraParametrs($productID); //related items $related = array(); $related_records = db_phquery_fetch(DBRFETCH_ROW_ALL, 'SELECT pr.productID as productID, ' . LanguagesManager::sql_prepareField('name') . ' AS name, Price, slug FROM ?#PRODUCTS_TABLE AS pr JOIN ?#RELATED_PRODUCTS_TABLE AS rel ON (rel.`productID` = pr.`productID`) WHERE Owner=? AND enabled = 1', $productID); foreach ($related_records as $r) { $r[2] = show_price($r[2]); $RelatedPictures = GetPictures($r['productID']); foreach ($RelatedPictures as $_RelatedPicture) { if (!$_RelatedPicture['default_picture']) { continue; } if (!file_exists(DIR_PRODUCTS_PICTURES . "/" . $_RelatedPicture['thumbnail'])) { break; } $r['pictures'] = array('default' => $_RelatedPicture); break; } $related[] = $r; }