Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
Arquivo: home.php Projeto: gblok/rsc
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
function f_data($products, $pagination = null, $sort = null)
{
    $offset = 0;
    $rows = CONF_PRODUCTS_PER_PAGE;
    if ($pagination) {
        extract($pagination);
    }
    //$order = ' ORDER BY ' . CONF_DEFAULT_SORT_ORDER;
    $order = ' ORDER BY viewed_times DESC';
    $limit = ' LIMIT ' . $offset . ',' . $rows;
    $sql = '
        SELECT DISTINCT
        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 productID IN(' . implode(', ', $products) . ')' . $order . $limit;
    $q = db_query($sql);
    //    fb($order, 'limit');
    //    fb($limit, 'limit');
    //    {assign var=x_img value="/img/w130-h130/"}
    //
    //    {if $smarty.const.CONF_MOD_REWRITE}
    //    {assign var=url value=$offer|@fu_make_url}
    //    {else}
    //    {assign var=url value="/index.php?productID=`$offer.productID`"}
    //    {/if}
    //    {if $offer.countdown} _countdown{/if}
    while ($row = db_fetch_assoc($q)) {
        _setPictures($row);
        $productID = $row["productID"];
        $extra = psGetExtra($productID);
        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);
        }
        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['ss'] = dizSpecialSet($productID);
        $price_row = priceRow($row);
        $data = array_merge($row, $price_row);
        $result[] = f_data_prod($data);
    }
    return $result;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
function priceСost($id, $price)
{
    $set = dizSpecialSet($id);
    if (!empty($set['countdown'])) {
        $discount = (int) $_SESSION['special_set']['countdown_discount'][$id];
        if (!empty($discount)) {
            $price = priceСostDiscount($price, $discount);
        }
    }
    return $price;
}