Example #1
0
function _importProduct($row, $dbc, $identity_column, $dbcPhotos, $updated_extra_option, $currentCategoryID)
{
    $row["not defined"] = "";
    $row[$identity_column] = trim($row[$identity_column]);
    //search for product within current category
    $q = db_query("select productID, categoryID, customers_rating  from " . PRODUCTS_TABLE . " where categoryID=" . (int) $currentCategoryID . " and " . xEscSQL($_POST["update_column"]) . " LIKE '" . xEscSQL(trim($row[$identity_column])) . "'");
    $rowdb = db_fetch_row($q);
    if (!$rowdb && $_POST["update_column"] == 'product_code') {
        //not found
        //search for product in all categories
        $q = db_query("select productID, categoryID, customers_rating  from " . PRODUCTS_TABLE . " where " . xEscSQL($_POST["update_column"]) . " LIKE '" . xEscSQL(trim($row[$identity_column])) . "'");
        $rowdb = db_fetch_row($q);
    }
    $currency = $_POST['currencyISO'] ? $_POST['currencyISO'] : CONF_DEFAULT_CURRENCY;
    if (strcmp($dbc['ISO'], "not defined")) {
        $currencyID = getCurrencyID($row[$dbc['ISO']]);
        $currency = $currencyID ? $currencyID : $currency;
    }
    if ($rowdb) {
        //update product info
        $productID = $rowdb["productID"];
        $rowdb = GetProduct($productID);
        if (strcmp($dbc["Price"], "not defined")) {
            $Price = $row[$dbc["Price"]];
            $Price = str_replace(" ", "", $Price);
            $Price = str_replace(",", ".", $Price);
            $Price = (double) $Price;
        } else {
            $Price = $rowdb["Price_admin"];
        }
        if (strcmp($dbc["list_price"], "not defined")) {
            $list_price = $row[$dbc["list_price"]];
            $list_price = str_replace(" ", "", $list_price);
            $list_price = str_replace(",", ".", $list_price);
            $list_price = (double) $list_price;
        } else {
            $list_price = $rowdb["list_price_base"];
        }
        if (strcmp($dbc["sort_order"], "not defined")) {
            $sort_order = (int) $row[$dbc["sort_order"]];
        } else {
            $sort_order = $rowdb["sort_order"];
        }
        if (strcmp($dbc["in_stock"], "not defined")) {
            $in_stock = (int) $row[$dbc["in_stock"]];
        } else {
            $in_stock = $rowdb["in_stock"];
        }
        if (strcmp($dbc["eproduct_filename"], "not defined")) {
            $eproduct_filename = $row[$dbc["eproduct_filename"]];
        } else {
            $eproduct_filename = $rowdb["eproduct_filename"];
        }
        if (strcmp($dbc["eproduct_available_days"], "not defined")) {
            $eproduct_available_days = (int) $row[$dbc["eproduct_available_days"]];
        } else {
            $eproduct_available_days = $rowdb["eproduct_available_days"];
        }
        if (strcmp($dbc["eproduct_download_times"], "not defined")) {
            $eproduct_download_times = (int) $row[$dbc["eproduct_download_times"]];
        } else {
            $eproduct_download_times = $rowdb["eproduct_download_times"];
        }
        if (strcmp($dbc["weight"], "not defined")) {
            $weight = (double) $row[$dbc["weight"]];
        } else {
            $weight = $rowdb["weight"];
        }
        if (strcmp($dbc["free_shipping"], "not defined")) {
            $free_shipping = trim($row[$dbc["free_shipping"]]) == "+" ? 1 : 0;
        } else {
            $free_shipping = $rowdb["free_shipping"];
        }
        if (strcmp($dbc["min_order_amount"], "not defined")) {
            $min_order_amount = (int) $row[$dbc["min_order_amount"]];
        } else {
            $min_order_amount = $rowdb["min_order_amount"];
        }
        if (strcmp($dbc["shipping_freight"], "not defined")) {
            $shipping_freight = (double) $row[$dbc["shipping_freight"]];
        } else {
            $shipping_freight = $rowdb["shipping_freight"];
        }
        if (strcmp($dbc["description"], "not defined")) {
            $description = $row[$dbc["description"]];
        } else {
            $description = $rowdb["description"];
        }
        if (strcmp($dbc["brief_description"], "not defined")) {
            $brief_description = $row[$dbc["brief_description"]];
        } else {
            $brief_description = $rowdb["brief_description"];
        }
        if (strcmp($dbc["product_code"], "not defined")) {
            $product_code = $row[$dbc["product_code"]];
        } else {
            $product_code = xHtmlSpecialCharsDecode($rowdb["product_code"]);
        }
        if (strcmp($dbc["meta_description"], "not defined")) {
            $meta_description = $row[$dbc["meta_description"]];
        } else {
            $meta_description = xHtmlSpecialCharsDecode($rowdb["meta_description"]);
        }
        if (strcmp($dbc["meta_keywords"], "not defined")) {
            $meta_keywords = $row[$dbc["meta_keywords"]];
        } else {
            $meta_keywords = xHtmlSpecialCharsDecode($rowdb["meta_keywords"]);
        }
        if (strcmp($dbc["name"], "not defined")) {
            $name = $row[$dbc["name"]];
        } else {
            $name = xHtmlSpecialCharsDecode($rowdb["name"]);
        }
        if (strcmp($dbc["title"], "not defined")) {
            $title = $row[$dbc["title"]];
        } else {
            $title = xHtmlSpecialCharsDecode($rowdb["title"]);
        }
        if (strcmp($dbc["sef"], "not defined")) {
            $sef = $row[$dbc["sef"]];
        } else {
            $sef = xHtmlSpecialCharsDecode($rowdb["sef"]);
        }
        $opt_margin = $rowdb["opt_margin"];
        $categoryID = $rowdb["categoryID"];
        $customers_rating = $rowdb["customers_rating"];
        $ProductIsProgram = trim($eproduct_filename) != "";
        UpdateProduct($productID, $categoryID, $name, $Price, $description, $in_stock, $customers_rating, $brief_description, $list_price, $product_code, $sort_order, $ProductIsProgram, "", $eproduct_available_days, $eproduct_download_times, $weight, $meta_description, $meta_keywords, $free_shipping, $min_order_amount, $shipping_freight, null, $currency, $opt_margin, $sef, $title, 0);
    } else {
        // add new product
        $Price = 0.0;
        $list_price = 0.0;
        $sort_order = 0;
        $in_stock = 0;
        $eproduct_filename = "";
        $eproduct_available_days = 0;
        $eproduct_download_times = 0;
        $weight = 0.0;
        $free_shipping = 0;
        $min_order_amount = 1;
        $shipping_freight = 0.0;
        if (strcmp($dbc["Price"], "not defined")) {
            $Price = (double) $row[$dbc["Price"]];
        }
        if (strcmp($dbc["list_price"], "not defined")) {
            $list_price = (double) $row[$dbc["list_price"]];
        }
        if (strcmp($dbc["sort_order"], "not defined")) {
            $sort_order = (int) $row[$dbc["sort_order"]];
        }
        if (strcmp($dbc["in_stock"], "not defined")) {
            $in_stock = (int) $row[$dbc["in_stock"]];
        }
        if (strcmp($dbc["eproduct_filename"], "not defined")) {
            $eproduct_filename = $row[$dbc["eproduct_filename"]];
        }
        if (strcmp($dbc["eproduct_available_days"], "not defined")) {
            $eproduct_available_days = (int) $row[$dbc["eproduct_available_days"]];
        }
        if (strcmp($dbc["eproduct_download_times"], "not defined")) {
            $eproduct_download_times = (int) $row[$dbc["eproduct_download_times"]];
        }
        if (strcmp($dbc["weight"], "not defined")) {
            $weight = (double) $row[$dbc["weight"]];
        }
        if (strcmp($dbc["free_shipping"], "not defined")) {
            $free_shipping = trim($row[$dbc["free_shipping"]]) == "+" ? 1 : 0;
        }
        if (strcmp($dbc["min_order_amount"], "not defined")) {
            $min_order_amount = (int) $row[$dbc["min_order_amount"]];
        }
        if (strcmp($dbc["shipping_freight"], "not defined")) {
            $shipping_freight = (double) $row[$dbc["shipping_freight"]];
        }
        $ProductIsProgram = trim($row[$dbc["eproduct_filename"]]) != "";
        $sef = $row[$dbc["sef"]];
        $productID = AddProduct($currentCategoryID, $row[$dbc["name"]], $Price, $row[$dbc["description"]], $in_stock, $row[$dbc["brief_description"]], $list_price, $row[$dbc["product_code"]], $sort_order, $ProductIsProgram, "", $eproduct_available_days, $eproduct_download_times, $weight, $row[$dbc["meta_description"]], $row[$dbc["meta_keywords"]], $free_shipping, $min_order_amount, $shipping_freight, CONF_DEFAULT_TAX_CLASS, $currency, 1, $sef, $row[$dbc["title"]], 0);
    }
    if (strlen($eproduct_filename)) {
        SetProductFile($productID, $eproduct_filename);
    }
    _importExtraOptionValues($row, $productID, $updated_extra_option);
    if (count($dbcPhotos) > 0) {
        _importProductPictures($row, $dbcPhotos, $productID);
    }
    if (!empty($sef)) {
        fu_generate_product($productID, $sef);
    }
}
Example #2
0
function _exportProducts($categoryID, &$f, $delimiter)
{
    global $picture_columns_count;
    global $extra_columns_count;
    //products
    $sql = '
    SELECT
    sort_order,
    product_code,
    name,
    description,
    brief_description,
    Price,
    list_price,
    in_stock,
    items_sold,
    meta_keywords,
    meta_description,
    shipping_freight,
    weight,
    free_shipping,
    min_order_amount,
    eproduct_filename,
    eproduct_available_days,
    eproduct_download_times,
    default_picture,
    productID,
    title,
    sef,
    currencyID
    FROM ' . PRODUCTS_TABLE . '
    WHERE categoryID=' . (int) $categoryID . '
    ORDER BY sort_order, name';
    $q1 = db_query($sql);
    //extra options
    $vararr = array();
    $q2 = db_query("select optionID from " . PRODUCT_OPTIONS_TABLE . " ORDER BY sort_order, name");
    while ($row2 = db_fetch_row($q2)) {
        $vararr[] = (int) $row2[0];
    }
    while ($row1 = db_fetch_row($q1)) {
        foreach ($row1 as $key => $val) {
            if (!strcmp($key, "Price") || !strcmp($key, "list_price")) {
                $val = round(100 * $val) / 100;
                if (round($val * 10) == $val * 10 && round($val) != $val) {
                    $val = (string) $val . "0";
                }
                //to avoid prices like 17.5 - write 17.50 instead
                $row1[$key] = $val;
            }
        }
        $lines = array($row1['sort_order'], xHtmlSpecialCharsDecode($row1['product_code']), xHtmlSpecialCharsDecode($row1['name']), xHtmlSpecialCharsDecode($row1['title']), xHtmlSpecialCharsDecode($row1['sef']), $row1['description'], $row1['brief_description'], $row1['Price'], getCurrencyISO($row1['currencyID']), $row1['list_price'], $row1['in_stock'], $row1['items_sold'], xHtmlSpecialCharsDecode($row1['meta_keywords']), xHtmlSpecialCharsDecode($row1['meta_description']), $row1['shipping_freight'], $row1['weight'], $row1['min_order_amount'], $row1['eproduct_filename'], $row1['eproduct_available_days'], $row1['eproduct_download_times']);
        //pictures
        //at first, fetch default picture
        $cnt = 0;
        if (!$row1["default_picture"]) {
            $row1["default_picture"] = 0;
        }
        //no default picture defined;
        $qp = db_query("select filename, thumbnail, enlarged from " . PRODUCT_PICTURES . " where productID=" . (int) $row1["productID"] . " and photoID=" . (int) $row1["default_picture"]);
        $rowp = db_fetch_row($qp);
        $s = "";
        if ($rowp) {
            if ($rowp[0]) {
                $s .= $rowp[0];
            }
            if ($rowp[1]) {
                $s .= "," . $rowp[1];
            } elseif ($rowp[2]) {
                $s .= ",";
            }
            if ($rowp[2]) {
                $s .= "," . $rowp[2];
            }
        }
        $lines[] = $s;
        $cnt++;
        //the rest of the photos
        $qp = db_query("select filename, thumbnail, enlarged from " . PRODUCT_PICTURES . " where productID=" . (int) $row1["productID"] . " and photoID!=" . (int) $row1["default_picture"]);
        while ($rowp = db_fetch_row($qp)) {
            $s = "";
            if ($rowp) {
                if ($rowp[0]) {
                    $s .= $rowp[0];
                }
                if ($rowp[1]) {
                    $s .= "," . $rowp[1];
                } elseif ($rowp[2]) {
                    $s .= ",";
                }
                if ($rowp[2]) {
                    $s .= "," . $rowp[2];
                }
            }
            $lines[] = $s;
            $cnt++;
        }
        if ($cnt < $picture_columns_count) {
            for ($i = $cnt; $i < $picture_columns_count; $i++) {
                $lines[] = "";
            }
        }
        //browse options list
        foreach ($vararr as $keyz => $extid) {
            //browser all option values of current product
            $q3 = db_query("select option_value, option_type, variantID from " . PRODUCT_OPTIONS_VALUES_TABLE . " where productID=" . (int) $row1['productID'] . " and optionID=" . $extid);
            $row3 = db_fetch_row($q3);
            if (!$row3) {
                $row3 = array("", 0, 0);
            }
            if ((int) $row3[1] == 1) {
                if (!$row3[2]) {
                    $row3[2] = 0;
                }
                //prepare an array of available option variantIDs. the first element (0'th) is the default varinatID
                $available_variants = array(array($row3[2], 0));
                $q4 = db_query("select variantID, price_surplus from " . PRODUCTS_OPTIONS_SET_TABLE . " where productID=" . (int) $row1['productID'] . " and optionID=" . $extid);
                while ($row4 = db_fetch_row($q4)) {
                    if ($row4[0] == $row3[2]) {
                        $available_variants[0] = $row4;
                    } else {
                        $available_variants[] = $row4;
                    }
                    //add this value to array
                }
                //now write all variants
                $s = "{";
                $tmp = "";
                foreach ($available_variants as $key => $val) {
                    if ($val[0]) {
                        $qvar = db_query("select option_value from " . PRODUCTS_OPTIONS_VALUES_VARIANTS_TABLE . " where optionID=" . $extid . " and variantID=" . (int) $val[0]);
                        $rowvar = db_fetch_row($qvar);
                        $s .= $tmp;
                        $s .= xHtmlSpecialCharsDecode($rowvar[0]) . "";
                        if ($val[1]) {
                            $s .= "=" . $val[1];
                        }
                        $tmp = ",";
                    }
                }
                $s .= "}";
                $row3[0] = $s;
            }
            $lines[] = $row3[0];
        }
        fputcsvex($f, $lines, $delimiter);
    }
}
Example #3
0
function xHtmlSpecialCharsDecode($_Data, $_Params = array(), $_Key = array())
{
    if (!is_array($_Data)) {
        return html_entity_decode($_Data, ENT_QUOTES);
    }
    if (!is_array($_Key)) {
        $_Key = array($_Key);
    }
    foreach ($_Data as $__Key => $__Data) {
        if (count($_Key) && !is_array($__Data)) {
            if (in_array($__Key, $_Key)) {
                $_Data[$__Key] = xHtmlSpecialCharsDecode($__Data, $_Params, $_Key);
            }
        } else {
            $_Data[$__Key] = xHtmlSpecialCharsDecode($__Data, $_Params, $_Key);
        }
    }
    return $_Data;
}