function getProductByBrand($brandID) { $sql = ' select categoryID, name, productID, default_picture, sort_order, enabled, product_code, uri, uri_opt_val ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' WHERE categoryID = ' . (int) $brandID . ' ORDER BY name'; $q = db_query($sql); $result = array(); while ($row = db_fetch_assoc($q)) { _setPictures($row); $row['url'] = fu_make_url($row); $result[] = $row; } return $result; }
function _exportProducts($f, $rate, $export_product_name, $categories_select) { if (!count($categories_select)) { return 0; } include_once "core/classes/class.html2text.php"; include_once "core/classes/class.htmlparser.php"; fputs($f, " <offers>\n"); //товары с нулевым остатком на складе if (isset($_POST["yandex_dont_export_negative_stock"])) { $clause = " and in_stock>0"; } else { $clause = ""; } //какое описание экспортировать if ($_POST["yandex_export_description"] == 1) { $dsc = "description"; $dsc_q = ", " . $dsc; } else { if ($_POST["yandex_export_description"] == 2) { $dsc = "brief_description"; $dsc_q = ", " . $dsc; } else { $dsc = ""; $dsc_q = ""; } } $clause .= " and categoryID IN (" . implode(", ", xEscSQL($categories_select)) . ")"; $sql = ' SELECT productID, name, Price, categoryID, default_picture' . $dsc_q . ', in_stock, uri, uri_opt_val ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' WHERE enabled=1' . $clause; $q = db_query($sql); $store_url = correct_URL(CONF_FULL_SHOP_URL); while ($product = db_fetch_row($q)) { $price_row = priceRow($product); $url = $store_url . fu_make_url($product); fputs($f, " <offer available=\"" . ($product['in_stock'] || !CONF_CHECKSTOCK ? 'true' : 'false') . "\" id=\"" . $product["productID"] . "\">\n"); fputs($f, " <url>" . $url . "</url>\n"); //fputs($f, " <price>" . roundf($product["Price"] * $rate) . "</price>\n"); fputs($f, " <price>" . $price_row['Price_base'] . "</price>\n"); fputs($f, " <currencyId>RUR</currencyId>\n"); fputs($f, " <categoryId>" . $product["categoryID"] . "</categoryId>\n"); if ($product["default_picture"] != NULL) { $pic_clause = " and photoID=" . (int) $product["default_picture"]; } else { $pic_clause = ""; } $q1 = db_query("select filename, thumbnail from " . PRODUCT_PICTURES . " where productID=" . (int) $product["productID"] . $pic_clause); $pic_row = db_fetch_row($q1); if ($pic_row) { if (strlen($pic_row["filename"]) && file_exists("data/small/" . $pic_row["filename"])) { fputs($f, " <picture>" . $store_url . "data/small/" . str_replace(' ', '%20', _deleteHTML_Elements($pic_row["filename"])) . "</picture>\n"); } else { if (strlen($pic_row["thumbnail"]) && file_exists("data/medium/" . $pic_row["thumbnail"])) { fputs($f, " <picture>" . $store_url . "data/medium/" . str_replace(' ', '%20', _deleteHTML_Elements($pic_row["thumbnail"])) . "</picture>\n"); } } } switch ($export_product_name) { default: case 'only_name': $_NameAddi = ''; break; case 'path_and_name': $_NameAddi = ''; $_t = catCalculatePathToCategory($product['categoryID']); foreach ($_t as $__t) { if ($__t['categoryID'] != 1) { $_NameAddi .= $__t['name'] . ':'; } } break; } $product["name"] = _deleteHTML_Elements($_NameAddi . $product["name"]); fputs($f, " <name>" . $product["name"] . "</name>\n"); if (strlen($dsc) > 0) { $product_dsc = new Html2Text($product[$dsc], 10000); $product_dsc = $product_dsc->convert(); fputs($f, " <description>" . _deleteHTML_Elements($product_dsc) . "</description>\n"); } else { fputs($f, " <description></description>\n"); } fputs($f, " </offer>\n"); } fputs($f, " </offers>\n"); }
function pricessCategories($parent, $level) { //same as processCategories(), except it creates a pricelist of the shop $out = array(); $cnt = 0; $sql = ' SELECT categoryID, name, uri FROM ' . CATEGORIES_TABLE . ' WHERE parent= ' . (int) $parent . ' ORDER BY sort_order, name'; $q1 = db_query($sql); while ($row = db_fetch_row($q1)) { $r = hexdec(substr('999999', 0, 2)); $g = hexdec(substr('999999', 2, 2)); $b = hexdec(substr('999999', 4, 2)); $m = (double) max($r, max($g, $b)); $r = round((190 + 20 * min($level, 3)) * $r / $m); $g = round((190 + 20 * min($level, 3)) * $g / $m); $b = round((190 + 20 * min($level, 3)) * $b / $m); $c = dechex($r) . dechex($g) . dechex($b); //final color //add category to the output $out[$cnt][0] = $row[0]; $out[$cnt][1] = $row[1]; $out[$cnt][2] = $level; $out[$cnt][3] = 1; $out[$cnt][4] = 0; //0 is for category, 1 - product $out[$cnt]['url'] = fu_make_url($row); $cnt++; if (!isset($_GET["sort"])) { $order_clause = "order by " . CONF_DEFAULT_SORT_ORDER . ""; } else { //verify $_GET["sort"] if (!(!strcmp($_GET["sort"], "name") || !strcmp($_GET["sort"], "Price") || !strcmp($_GET["sort"], "customers_rating"))) { $_GET["sort"] = "name"; } $order_clause = " order by " . xEscSQL($_GET["sort"]); if (isset($_GET["direction"])) { if (!strcmp($_GET["direction"], "DESC")) { $order_clause .= " DESC "; } else { $order_clause .= " ASC "; } } } //add products // Price, // in_stock, $sql = ' SELECT productID, name, product_code, uri, uri_opt_val, categoryID ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' WHERE categoryID=' . $row[0] . ' AND Price > 0 AND enabled=1 ' . $order_clause; $q = db_query($sql); while ($row1 = db_fetch_row($q)) { if ($row1['Price'] < 0) { $cennik = "n/a"; $row1['Price'] = "n/a"; } else { $cennik = show_price($row1['Price']); $row1['Price'] = show_price($row1['Price'], 0, false); } $out[$cnt][0] = $row1['productID']; $out[$cnt][1] = $row1['name']; $out[$cnt][2] = $level; $out[$cnt][3] = "FFFFFF"; $out[$cnt][4] = 1; //0 is for category, 1 - product $out[$cnt][5] = $cennik; $out[$cnt][6] = $row1['in_stock']; $out[$cnt][7] = $row1['product_code']; $out[$cnt][8] = $row1['Price']; $out[$cnt]['url'] = fu_make_url($row1); $cnt++; } //process all subcategories $sub_out = pricessCategories($row[0], $level + 1); //add $sub_out to the end of $out $c_sub_out = count($sub_out); for ($j = 0; $j < $c_sub_out; $j++) { $out[] = $sub_out[$j]; $cnt++; } } return $out; }
function GetPriceProductWithOption($variants, $productID) { $sql = ' SELECT productID, currencyID ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' WHERE productID=' . (int) $productID; $q = db_query($sql); while ($row = db_fetch_row($q)) { $row['ss'] = dizSpecialSet($row['productID']); $price_row = priceRow($row); $full_price = $price_row['Price_base']; } if (is_array($variants)) { foreach ($variants as $vars) { $sql = ' SELECT price_surplus FROM ' . PRODUCTS_OPTIONS_SET_TABLE . ' WHERE productID=' . (int) $productID . ' AND variantID=' . (int) $vars; $q1 = db_query($sql); $r1 = db_fetch_row($q1); $full_price += $r1['price_surplus']; } } return $full_price; }
Redirect(ADMIN_FILE . "?dpt=catalog&sub=countdown&module=" . $moduleID); } //Get productID from COUNTDOWN table $sql = ' SELECT * FROM ' . COUNTDOWN_OFFERS_TABLE . ' WHERE moduleID=' . $moduleID . ' ORDER BY sort_order'; $q = db_query($sql); $result = array(); while ($row = db_fetch_row($q)) { //get product name $sql = ' SELECT name ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' WHERE productID=' . (int) $row['productID']; $p = db_query($sql); if ($row1 = db_fetch_row($p)) { $row['name'] = $row1['name']; $row['price'] = $row1['price']; $price_row = priceRow($row1); $row['new_price'] = show_price(priceСostDiscount($price_row['Price_base'], $row['discount'])); $result[] = array_merge($row, $price_row); } } // debug($result); $smarty->assign("offers", $result); $smarty->assign("admin_sub_dpt", "catalog_countdown.tpl"); }
function h_spec_offers() { $result = array(); // s.Price, // s.list_price, $sql = ' SELECT s.productID, s.categoryID, s.name, s.brief_description, s.product_code, s.default_picture, s.enabled, s.opt_margin, b.productID, t.filename, s.uri, s.uri_opt_val ' . convert_prices() . ' FROM ' . SPECIAL_OFFERS_TABLE . ' AS b INNER JOIN ' . PRODUCTS_TABLE . ' AS s on (b.productID=s.productID) INNER JOIN ' . PRODUCT_PICTURES . ' AS t on (s.default_picture=t.photoID AND s.productID=t.productID) WHERE s.enabled=1 ORDER BY b.sort_order'; //fbug($sql); $q = db_query($sql); while ($row = db_fetch_row($q)) { $row['picture'] = $row['filename']; $extra = psGetExtra($row['productID']); if (!empty($extra)) { $row['product_extra'] = $extra; $row['product_extra_count'] = count($extra); $pre_extra = array(); $pre_extra[$row['productID']] = $extra; $row['color'] = psGetColor($row['productID'], $pre_extra); $resource = psGetExtraVal('resource', $pre_extra, $row['productID']); if ($resource) { $row['resource'] = ' <span class="resource">' . $resource . ' стр.</span>'; } } $row['sname'] = replace_name($row['name']); $row['ss'] = dizSpecialSet($row['productID']); $price_row = priceRow($row); $result[] = array_merge($row, $price_row); } //fbug($result); //$smarty->assign('special_offers', $result); return $result; }
function psGetRelatedProducts($products, $extra = null) { if (is_array($products)) { $sql = ' SELECT s.productID, s.categoryID, s.name, s.uri, s.uri_opt_val, p.filename AS src ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' AS s LEFT JOIN ' . PRODUCT_PICTURES . ' AS p ON (s.default_picture=p.photoID AND s.productID=p.productID) WHERE s.productID IN (' . implode(',', $products) . ') AND s.enabled=1 ORDER by s.name'; $q = db_query($sql); $result = array(); while ($row = db_fetch_assoc($q)) { if (!empty($extra)) { $row["color"] = psGetColor($row["productID"], $extra); $row["resource"] = psGetVal('resource', $extra, $row["productID"]); } $row['name'] = trim(str_replace(array('Оригинальный', 'Совместимый'), '', $row['name'])); $row['url'] = fu_make_url($row); $row['ss'] = dizSpecialSet($row['productID']); $price_row = priceRow($row); $result[] = array_merge($row, $price_row); } } return $result; }
function f_products($categories, $conditions = null) { $where = 'categoryID IN(' . implode(', ', $categories) . ')'; $additional = f_additional($categories); if ($additional) { $where = '(' . $where . ' OR productID IN(' . implode(', ', $additional) . ')'; } if ($conditions['price']) { $from = (int) $conditions['price']['from']; $to = (int) $conditions['price']['to']; // $price_range = ' AND Price BETWEEN ' . $conditions['price']['from'] . ' AND ' . $conditions['price']['to']; } $sql = ' SELECT DISTINCT productID ' . convert_prices(array('Price')) . ' FROM ' . PRODUCTS_TABLE . ' WHERE ' . $where . ' AND enabled = 1 AND price > 0'; $q = db_query($sql); // fb($sql); while ($row = db_fetch_assoc($q)) { $price = $row['Price']; $productID = $row['productID']; //fb($price); if ($conditions['price'] && $price >= $from && $price <= $to) { $products[] = $productID; } $all_products[$productID] = $price; } $result['products'] = $products ? $products : array_keys($all_products); $result['all_products'] = $all_products; return $result; }
function prdSearchProductByTemplate($callBackParam, &$count_row, $navigatorParams = null) { // navigator params if ($navigatorParams != null) { $offset = xEscSQL($navigatorParams["offset"]); $CountRowOnPage = xEscSQL($navigatorParams["CountRowOnPage"]); } else { $offset = 0; $CountRowOnPage = 0; } if (isset($callBackParam["extraParametrsTemplate"])) { $replicantExtraParametersTpl = $callBackParam["extraParametrsTemplate"]; } // special symbol prepare if (isset($callBackParam["search_simple"])) { /* for( $i=0; $i<count($callBackParam["search_simple"]); $i++ ) { $callBackParam["search_simple"][$i] = $callBackParam["search_simple"][$i]; } */ _deletePercentSymbol($callBackParam["search_simple"]); } if (isset($callBackParam["name"])) { for ($i = 0; $i < count($callBackParam["name"]); $i++) { $callBackParam["name"][$i] = xToText(trim($callBackParam["name"][$i])); } _deletePercentSymbol($callBackParam["name"][$i]); } if (isset($callBackParam["product_code"])) { for ($i = 0; $i < count($callBackParam["product_code"]); $i++) { $callBackParam["product_code"][$i] = xToText(trim($callBackParam["product_code"][$i])); } _deletePercentSymbol($callBackParam["product_code"]); } if (isset($callBackParam["extraParametrsTemplate"])) { foreach ($callBackParam["extraParametrsTemplate"] as $key => $value) { if (is_int($key)) { $callBackParam["extraParametrsTemplate"][$key] = xEscSQL(trim($callBackParam["extraParametrsTemplate"][$key])); _deletePercentSymbol($callBackParam["extraParametrsTemplate"][$key]); } } } $where_clause = ""; if (isset($callBackParam['tid'])) { $where_clause = 'WHERE productID IN (' . implode(',', $callBackParam['tid']) . ')'; // if (!count($callBackParam["search_simple"])) { //empty array // $where_clause = " where 0"; // } else { //search array is not empty // $sscount = count($callBackParam["search_simple"]); // for ($n = 0; $n < $sscount; $n++) { // if ($where_clause != "") // $where_clause .= " AND "; // $where_clause .= " ( LOWER(name) LIKE '%" . xToText(trim(strtolower($callBackParam["search_simple"][$n]))) . "%' OR " . // " LOWER(description) LIKE '%" . xEscSQL(trim(strtolower($callBackParam["search_simple"][$n]))) . "%' OR " . // " LOWER(product_code) LIKE '%" . xEscSQL(trim(strtolower($callBackParam["search_simple"][$n]))) . "%' OR " . // " LOWER(brief_description) LIKE '%" . xEscSQL(trim(strtolower($callBackParam["search_simple"][$n]))) . "%' ) "; // } // // if ($where_clause != "") { // $where_clause = " where categoryID>1 and enabled=1 and " . $where_clause; // } else { // $where_clause = " where categoryID>1 and enabled=1"; // } // // if (CONF_CHECKSTOCK && CONF_SHOW_NULL_STOCK) { // if ($where_clause != "") // $where_clause .= " AND in_stock>0 "; // else // $where_clause = "where in_stock>0 "; // } // } } else { // "enabled" parameter if (isset($callBackParam["enabled"])) { if ($where_clause != "") { $where_clause .= " AND "; } $where_clause .= " enabled=" . (int) $callBackParam["enabled"]; } // take into "name" parameter if (isset($callBackParam["name"])) { foreach ($callBackParam["name"] as $name) { if (strlen($name) > 0) { if ($where_clause != "") { $where_clause .= " AND "; } $where_clause .= " LOWER(name) LIKE '%" . xToText(trim(strtolower($name))) . "%' "; } } } // take into "product_code" parameter if (isset($callBackParam["product_code"])) { foreach ($callBackParam["product_code"] as $product_code) { if ($where_clause != "") { $where_clause .= " AND "; } $where_clause .= " LOWER(product_code) LIKE '%" . xToText(trim(strtolower($product_code))) . "%' "; } } // take into "price" parameter if (isset($callBackParam["price"])) { $price = $callBackParam["price"]; if (trim($price["from"]) != "" && $price["from"] != null) { if ($where_clause != "") { $where_clause .= " AND "; } $from = ConvertPriceToUniversalUnit($price["from"]); $where_clause .= " Price>=" . (double) $from . " "; } if (trim($price["to"]) != "" && $price["to"] != null) { if ($where_clause != "") { $where_clause .= " AND "; } $to = ConvertPriceToUniversalUnit($price["to"]); $where_clause .= " Price<=" . (double) $to . " "; } } if (CONF_CHECKSTOCK && CONF_SHOW_NULL_STOCK) { if ($where_clause != "") { $where_clause .= " AND in_stock>0 "; } else { $where_clause = "where in_stock>0 "; } } // categoryID if (isset($callBackParam["categoryID"])) { $searchInSubcategories = false; if (isset($callBackParam["searchInSubcategories"])) { if ($callBackParam["searchInSubcategories"]) { $searchInSubcategories = true; } else { $searchInSubcategories = false; } } if ($searchInSubcategories) { $where_clause = _getConditionWithCategoryConjWithSubCategories($where_clause, $callBackParam["categoryID"]); } else { $where_clause = _getConditionWithCategoryConj($where_clause, $callBackParam["categoryID"]); } } if ($where_clause != "") { $where_clause = "where " . $where_clause; } } $order_by_clause = "ORDER BY " . CONF_DEFAULT_SORT_ORDER . ""; if (isset($callBackParam["sort"])) { if ($callBackParam["sort"] == "categoryID" || $callBackParam["sort"] == "name" || $callBackParam["sort"] == "brief_description" || $callBackParam["sort"] == "in_stock" || $callBackParam["sort"] == "Price" || $callBackParam["sort"] == "customer_votes" || $callBackParam["sort"] == "customers_rating" || $callBackParam["sort"] == "list_price" || $callBackParam["sort"] == "sort_order" || $callBackParam["sort"] == "items_sold" || $callBackParam["sort"] == "product_code" || $callBackParam["sort"] == "shipping_freight" || $callBackParam["sort"] == "viewed_times") { $order_by_clause = " order by " . xEscSQL($callBackParam["sort"]) . " ASC "; if (isset($callBackParam["direction"])) { if ($callBackParam["direction"] == "DESC") { $order_by_clause = " order by " . xEscSQL($callBackParam["sort"]) . " DESC "; } } } } if (isset($callBackParam['tid'])) { $products_count = count($callBackParam['tid']); } else { $sql = "select count(*) from " . PRODUCTS_TABLE . " " . $where_clause; $q = db_query($sql); $products_count = db_fetch_row($q); $products_count = $products_count[0]; } $limit_clause = isset($callBackParam["extraParametrsTemplate"]) || !$CountRowOnPage ? "" : " LIMIT " . $offset . "," . $CountRowOnPage; $sql = ' select categoryID, name, in_stock, productID, default_picture, sort_order, enabled, product_code, shipping_freight, min_order_amount, opt_margin, uri, uri_opt_val ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' ' . $where_clause . ' ' . $order_by_clause . $limit_clause; // viewed_times, // brief_description, // customers_rating, // customer_votes, // items_sold, // description, // fb($sql); $q = db_query($sql); $result = array(); $i = 0; if ($offset >= 0 && $offset <= $products_count) { while ($row = db_fetch_row($q)) { // if (isset($callBackParam["extraParametrsTemplate"])) { // // // take into "extra" parametrs // $testResult = _testExtraParametrsTemplate($row["productID"], $replicantExtraParametersTpl); // if (!$testResult) // continue; // } if (($i >= $offset || !isset($callBackParam["extraParametrsTemplate"])) && $i < $offset + $CountRowOnPage || $navigatorParams == null) { _setPictures($row); $productID = $row["productID"]; $extra = psGetExtra($productID); // if($extra){ // foreach($extra as $options){ // // } // } // if (!empty($extra)) { $row["product_extra"] = $extra; $row["product_extra_count"] = count($extra); $pre_extra = array(); $pre_extra[$productID] = $extra; $row["color"] = psGetColor($productID, $pre_extra); $row["color"] = psGetColor($productID, $pre_extra); $resource = psGetExtraVal('resource', $pre_extra, $row['productID']); // // fbd($extra); } if ((double) $row["shipping_freight"] > 0) { $row["shipping_freightUC"] = show_price($row["shipping_freight"]); } $row["name"] = $row["name"]; $row["sname"] = replace_name($row['name']); $row["description"] = $row["description"]; $row["brief_description"] = $row["brief_description"]; $row["product_code"] = $row["product_code"]; $row["viewed_times"] = $row["viewed_times"]; $row["items_sold"] = $row["items_sold"]; $row['ss'] = dizSpecialSet($productID); $price_row = priceRow($row); if (!empty($extra)) { if ($resource) { if ($price_row['Price_base'] > 0) { $cost_print = number_format($price_row['Price_base'] / $resource, 2, '.', ''); $row['cost_print'] = '<span class="resource">' . $cost_print . ' р. стр.</span>'; } $row['resource'] = ' <span class="resource">' . $resource . ' стр.</span>'; } } $result[] = array_merge($row, $price_row); } $i++; } } // $count_row = isset($callBackParam["extraParametrsTemplate"]) ? $i : $products_count; // fbug($count_row); $count_row = $products_count; return $result; }
function dizGetCountDown() { $result = array(); $products = array(); $countdowns = array(); $_SESSION['special_set']['countdown'] = array(); $_SESSION['special_set']['countdown_discount'] = array(); $sql = ' SELECT productID, countdown, discount FROM ' . COUNTDOWN_OFFERS_TABLE . ' WHERE countdown BETWEEN DATE_SUB(utc_timestamp(), INTERVAL -1 SECOND) AND DATE_SUB(utc_timestamp(), INTERVAL - 9 DAY) ORDER BY sort_order'; $q = db_query($sql); // DATE_SUB(NOW(), INTERVAL - 1 SECOND) // WHERE (countdown > NOW() AND countdown < DATE_SUB(NOW(), INTERVAL - 9 DAY)) while ($row = db_fetch_assoc($q)) { $products[] = $row['productID']; $_SESSION['special_set']['countdown'][] = $row['productID']; $_SESSION['special_set']['countdown_discount'][$row['productID']] = $row['discount']; $_SESSION['special_set']['countdown_time'][$row['productID']] = date('Y:m:j:H:i:s', strtotime($row['countdown'])); // fbug(date('Y:m:j:H:i:s', strtotime($row['countdown']))); } if ($products) { $sql = ' SELECT p.productID, p.categoryID, p.name, p.brief_description, p.product_code, p.default_picture, p.enabled, p.opt_margin, i.filename, p.uri, p.uri_opt_val ' . convert_prices() . ' FROM ' . PRODUCTS_TABLE . ' AS p INNER JOIN ' . PRODUCT_PICTURES . ' AS i ON (p.default_picture = i.photoID AND p.productID = i.productID) WHERE p.productID IN (' . implode(',', $products) . ') AND p.enabled=1 AND p.price > 0 AND p.default_picture IS NOT NULL ORDER BY FIELD(p.productID, ' . implode(',', $products) . ')'; $q = db_query($sql); while ($row = db_fetch_assoc($q)) { // $productID = $row['productID']; // if (!empty($countdowns)) { // if (array_key_exists($productID, $countdowns)) { // $row['remaining'] = strtotime($countdowns[$productID]) - strtotime(date('Y-m-d H:i:s', time())); // $row['countdown'] = date('Y:m:j:H:i:s', strtotime($countdowns[$productID])); // } // } $extra = psGetExtra($row["productID"]); if (!empty($extra)) { $row["product_extra"] = $extra; $row["product_extra_count"] = count($extra); $pre_extra = array(); $pre_extra[$row["productID"]] = $extra; $row["color"] = psGetColor($row["productID"], $pre_extra); } $row['picture'] = $row['filename']; $row['ss'] = dizSpecialSet($row['productID']); $price_row = priceRow($row); $result[] = array_merge($row, $price_row); } } return $result; }