示例#1
0
 /**
  * Получаем категории из XML и добавляем их
  * @param $xml
  */
 function GetFromXML($xml)
 {
     global $tpl, $mysql, $twig, $parse;
     $update = 0;
     foreach ($xml as $xml_cat) {
         $NAME = iconv('utf-8', 'windows-1251', (string) $xml_cat);
         $UF_ID = (int) $xml_cat->attributes()->id;
         $UF_PARENT_ID = (int) $xml_cat->attributes()->parentId;
         if (!in_array($UF_ID, $_SESSION['cats_uf_ids'])) {
             $URL = strtolower($parse->translit($NAME, 1, 1));
             $URL = str_replace("/", "-", $URL);
             if ($URL) {
                 if (!is_array($mysql->record("select id from " . prefix . "_eshop_categories where url = " . db_squote($URL) . " limit 1"))) {
                     $mysql->query('INSERT INTO ' . prefix . '_eshop_categories (id, name, url, meta_title, parent_id) 
                         VALUES 
                         (   ' . db_squote($UF_ID) . ',
                             ' . db_squote($NAME) . ',
                             ' . db_squote($URL) . ',
                             ' . db_squote($NAME) . ',
                             ' . db_squote($UF_PARENT_ID) . '
                         )
                     ');
                     $this->Add2Session($UF_ID, $NAME, $URL, $UF_ID, $UF_PARENT_ID);
                     generate_catz_cache(true);
                     $this->eco('Добавлена категория: ' . $NAME . '<br>');
                     $update++;
                 }
             }
         }
     }
     $this->eco('Количество XML категорий: ' . count($xml) . ' шт.<br>');
     $this->eco('Добавлено ' . $update . ' категорий.<br>');
 }
示例#2
0
function del_cat($params)
{
    global $mysql;
    $id = intval($_REQUEST['id']);
    if (empty($id)) {
        return msg(array("type" => "error", "text" => "Ошибка, вы не выбрали что хотите удалить"));
    }
    $cnt_products_in_cat = $mysql->record('SELECT COUNT(*) AS cnt FROM ' . prefix . '_eshop_products_categories WHERE category_id = ' . db_squote($id) . '');
    if ($cnt_products_in_cat['cnt'] == 0) {
        $row = $mysql->record('SELECT * FROM ' . prefix . '_eshop_categories WHERE id = ' . db_squote($id) . ' LIMIT 1');
        delete_cat_image($row['image']);
        $mysql->query("DELETE FROM " . prefix . "_eshop_categories WHERE id = {$id}");
        msg(array("type" => "info", "info" => "Категория удалена"));
        generate_catz_cache(true);
    } else {
        msg(array("type" => "info", "info" => "Категория не может быть удалена, т.к. в ней есть продукция"));
    }
}
示例#3
0
function plugin_m_eshop_catz_tree($overrideTemplateName)
{
    global $config, $twig;
    $eshop_dir = get_plugcfg_dir('eshop');
    generate_catz_cache();
    if (file_exists($eshop_dir . '/cache_catz.php')) {
        $tVars = unserialize(file_get_contents($eshop_dir . '/cache_catz.php'));
        if ($overrideTemplateName) {
            $templateName = 'block/' . $overrideTemplateName;
        } else {
            $templateName = 'block/block_cats_tree';
        }
        $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
        $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
        $output = $xt->render($tVars);
    } else {
        $output = '';
    }
    return $output;
}
示例#4
0
function eshop_infovars_show()
{
    global $CurrentHandler, $SYSTEM_FLAGS, $template, $lang, $mysql, $twig, $userROW, $ngCookieDomain;
    $SYSTEM_FLAGS["eshop"]["description_delivery"] = pluginGetVariable('eshop', 'description_delivery');
    $SYSTEM_FLAGS["eshop"]["description_order"] = pluginGetVariable('eshop', 'description_order');
    $SYSTEM_FLAGS["eshop"]["description_phones"] = pluginGetVariable('eshop', 'description_phones');
    $eshop_dir = get_plugcfg_dir('eshop');
    generate_currency_cache();
    if (file_exists($eshop_dir . '/cache_currency.php')) {
        $currency_tEntry = unserialize(file_get_contents($eshop_dir . '/cache_currency.php'));
    } else {
        $currency_tEntry = array();
    }
    /*
        $currency_link = checkLinkAvailable('eshop', 'currency')?
                generateLink('eshop', 'currency', array()):
                generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'currency'), array());
    
        $currency_tEntry = array();
        foreach ($mysql->select("SELECT * FROM ".prefix."_eshop_currencies WHERE enabled = 1 ORDER BY position, id") as $row)
        {
            $row['currency_link'] = $currency_link."?id=".$row['id'];
            $currency_tEntry[] = $row;
        }
    */
    $SYSTEM_FLAGS["eshop"]["currency"] = $currency_tEntry;
    $current_currency = array();
    if (!isset($_COOKIE['ngCurrencyID'])) {
        $ngCurrencyID = $currency_tEntry[0]['id'];
        $current_currency = $currency_tEntry[0];
        @setcookie('ngCurrencyID', $ngCurrencyID, time() + 86400 * 365, '/', $ngCookieDomain, 0, 1);
    } else {
        $ngCurrencyID = $_COOKIE['ngCurrencyID'];
        foreach ($currency_tEntry as $cc) {
            if ($cc['id'] == $ngCurrencyID) {
                $current_currency = $cc;
            }
        }
        if (empty($current_currency)) {
            $current_currency = $currency_tEntry[0];
        }
    }
    $SYSTEM_FLAGS["eshop"]["current_currency"] = $current_currency;
    generate_catz_cache();
    if (file_exists($eshop_dir . '/cache_catz.php')) {
        $catz_tEntry = unserialize(file_get_contents($eshop_dir . '/cache_catz.php'));
    } else {
        $catz_tEntry = array();
    }
    $SYSTEM_FLAGS["eshop"]["catz"] = $catz_tEntry;
    generate_features_cache();
    if (file_exists($eshop_dir . '/cache_features.php')) {
        $features_tEntry = unserialize(file_get_contents($eshop_dir . '/cache_features.php'));
    } else {
        $features_tEntry = array();
    }
    $SYSTEM_FLAGS["eshop"]["features"] = $features_tEntry;
    generate_categories_features_cache();
    if (file_exists($eshop_dir . '/cache_categories_features.php')) {
        $categories_features_tEntry = unserialize(file_get_contents($eshop_dir . '/cache_categories_features.php'));
    } else {
        $categories_features_tEntry = array();
    }
    $SYSTEM_FLAGS["eshop"]["categories_features"] = $categories_features_tEntry;
    $twig->addFunction('IsCatFeatures', new Twig_Function_Function('IsCatFeatures'));
    $filter = array();
    if (is_array($userROW)) {
        $filter[] = '(user_id = ' . db_squote($userROW['id']) . ')';
    }
    if (isset($_COOKIE['ngTrackID']) && $_COOKIE['ngTrackID'] != '') {
        $filter[] = '(cookie = ' . db_squote($_COOKIE['ngTrackID']) . ')';
    }
    $compare_link = checkLinkAvailable('eshop', 'compare') ? generateLink('eshop', 'compare', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'compare'), array());
    $basket_link = checkLinkAvailable('eshop', 'ebasket_list') ? generateLink('eshop', 'ebasket_list', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'ebasket_list'), array());
    if (count($filter) > 0) {
        $tCount = 0;
        $tEntries = array();
        foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_compare WHERE " . join(" or ", $filter) . "") as $row) {
            $tEntries[] = $row;
            $tCount += 1;
        }
        $compare_tVars = array('count' => $tCount, 'link' => $compare_link, 'entries' => $tEntries);
        $tCount = 0;
        $tPrice = 0;
        $tEntries = array();
        foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_ebasket WHERE " . join(" or ", $filter) . "") as $row) {
            $tEntries[] = $row;
            $tCount += 1;
            $tPrice += $row['price'] * $row['count'];
        }
        $basket_tVars = array('count' => $tCount, 'price' => $tPrice, 'entries' => $tEntries, 'basket_link' => $basket_link);
    } else {
        $compare_tVars = array('count' => 0, 'link' => $compare_link, 'entries' => array());
        $basket_tVars = array('count' => 0, 'price' => 0, 'entries' => array(), 'basket_link' => $basket_link);
    }
    $SYSTEM_FLAGS["eshop"]["compare"] = $compare_tVars;
    $SYSTEM_FLAGS["eshop"]["basket"] = $basket_tVars;
}
示例#5
0
function update_prices($change_price_type, $change_price_qnt)
{
    global $tpl, $mysql, $twig, $parse, $SYSTEM_FLAGS;
    if ($change_price_type == 1) {
        $newprice = (100 + $change_price_qnt) / 100;
    } else {
        $newprice = (100 - $change_price_qnt) / 100;
    }
    $mysql->query('UPDATE ' . prefix . '_eshop_variants SET price = price*' . $newprice . ', compare_price = compare_price*' . $newprice . ' ');
    generate_catz_cache(true);
}
示例#6
0
function import_yml($yml_url)
{
    global $tpl, $mysql, $twig, $parse, $SYSTEM_FLAGS;
    include_once dirname(__FILE__) . '/import.class.php';
    $file = file_get_contents($_REQUEST['yml_url']);
    $xml = new SimpleXMLElement($file);
    unset($file);
    unset($_SESSION['cats'], $_SESSION['cats_uf_ids'], $_SESSION['update'], $_SESSION['offers'], $_SESSION['IDS'], $_SESSION['j'], $_SESSION['page'], $_SESSION['work']);
    foreach ($xml->shop->offers->offer as $key => $offer) {
        $_SESSION['work'][] = (int) $offer->attributes()->id;
    }
    $ctg = new YMLCategory();
    $ctg->GetFromSite();
    $ctg->GetFromXML($xml->shop->categories->category);
    $ofs = new YMLOffer();
    foreach ($xml->shop->offers->offer as $key => $offer) {
        $oif = (int) $offer->attributes()->id;
        $name = iconv('utf-8', 'windows-1251', (string) $offer->name);
        if ($name == "") {
            $name = iconv('utf-8', 'windows-1251', trim((string) $offer->model . " " . (string) $offer->barcode));
        }
        if ($name != "") {
            $url = strtolower($parse->translit($name, 1, 1));
            $url = str_replace("/", "-", $url);
        }
        if ($url) {
            $prd_row = $mysql->record("select * from " . prefix . "_eshop_products where url = " . db_squote($url) . " limit 1");
            if (!is_array($prd_row)) {
                $oid = $ofs->Add($offer, $name, $url);
                $ofs->eco('Добавлен товар: ' . $name . '<br>');
            } else {
                $oid = $ofs->Update($prd_row['id'], $offer);
                $ofs->eco('Обновлен товар: ' . $name . '<br>');
            }
        }
    }
    generate_catz_cache(true);
}