}
 //get selected category info
 $q = db_query("SELECT categoryID, " . LanguagesManager::sql_prepareField('name') . " AS name, " . LanguagesManager::sql_prepareField('description') . " AS description, picture FROM " . CATEGORIES_TABLE . " WHERE categoryID='{$categoryID}'") or die(db_error());
 $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;
Exemple #2
0
         $definedOptions[] = $option;
     }
 }
 $optionIndex = 0;
 foreach ($definedOptions as $option) {
     $productIndex = 0;
     foreach ($products as $product) {
         $existFlag = false;
         foreach ($product["option_values"] as $optionValue) {
             if ($optionValue["optionID"] == $option["optionID"]) {
                 if ($optionValue["option_type"] == 0 && $optionValue["value"] != "") {
                     $value = $optionValue["value"];
                 } else {
                     if ($optionValue["option_type"] == 1) {
                         $value = "";
                         $extra = GetExtraParametrs($product["productID"]);
                         foreach ($extra as $item) {
                             if ($item["option_type"] == 1 && $item["optionID"] == $optionValue["optionID"] && isset($item["values_to_select"]) && count($item["values_to_select"]) > 0) {
                                 foreach ($item["values_to_select"] as $value_to_select) {
                                     if ($value != "") {
                                         $value .= " / " . $value_to_select["option_valueWithOutPrice"];
                                     } else {
                                         $value .= $value_to_select["option_valueWithOutPrice"];
                                     }
                                 }
                             }
                         }
                     } else {
                         $value = STRING_VALUE_IS_UNDEFINED;
                     }
                 }
Exemple #3
0
function prdSearchProductByTemplateAdmin($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["search_simple"])) {
        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";
            }
        }
    } 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 . " ";
            }
        }
        // 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"] == "currencyID" || $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 ";
                }
            }
        }
    }
    $sqlQueryCount = "select count(*) from " . PRODUCTS_TABLE . " " . $where_clause;
    $q = db_query($sqlQueryCount);
    $products_count = db_fetch_row($q);
    $products_count = $products_count[0];
    $limit_clause = isset($callBackParam["extraParametrsTemplate"]) || !$CountRowOnPage ? "" : " LIMIT " . $offset . ", " . $CountRowOnPage;
    $sqlQuery = '
        SELECT *' . convert_prices() . '
        FROM ' . PRODUCTS_TABLE . ' ' . $where_clause . ' ' . $order_by_clause . $limit_clause;
    $q = db_query($sqlQuery);
    $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);
                $row["product_extra"] = GetExtraParametrs($row["productID"]);
                $row["product_extra_count"] = count($row["product_extra"]);
                if ((double) $row["shipping_freight"] > 0) {
                    $row["shipping_freightUC"] = show_price($row["shipping_freight"]);
                }
                $row["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['Price_admin'] = $row['Price_base'];
                $row['list_price_admin'] = $row['list_price_base'];
                $price_row = priceRow($row);
                $result[] = array_merge($row, $price_row);
            }
            $i++;
        }
    }
    $count_row = isset($callBackParam["extraParametrsTemplate"]) ? $i : $products_count;
    return $result;
}