function smarty_function_currency($params, $smarty)
{
    if (isset($params['get'])) {
        switch ($params['get']) {
            case 'ind':
                if (!empty($params['id']) and (int) $params['id']) {
                    return model_corecatalog_currcalc::getCurrencyByID($params['id']);
                } else {
                    return model_corecatalog_currcalc::currInd();
                }
                break;
            case 'shortname':
                return model_corecatalog_currcalc::currShortName();
                break;
            case 'name':
                return model_corecatalog_currcalc::currName();
                break;
            default:
                throw new rad_exception("currency: wrong argument for 'get' parameter", E_USER_WARNING);
                break;
        }
    }
    if (!isset($params['cost'])) {
        throw new rad_exception("currency: missing 'cost' parameter", E_USER_WARNING);
    }
    if (!isset($params['curid'])) {
        throw new rad_exception("currency: missing 'curid' parameter", E_USER_WARNING);
    }
    $cost = empty($params['noconvert']) ? model_corecatalog_currcalc::calcCours($params['cost'], (int) $params['curid']) : $params['cost'];
    return empty($params['noformat']) ? model_corecatalog_currcalc::formatCost($cost, empty($params['noconvert']) ? null : (int) $params['curid']) : $cost;
}
Example #2
0
 function __construct()
 {
     if ($this->getParamsObject()) {
         $params = $this->getParamsObject();
         $this->_itemsperpage = $params->_get('itemsperpage', $this->_itemsperpage);
         $this->setVar('params', $params);
         if ($params->_get('type_show', false)) {
             //last products and other onmain
             $model = rad_instances::get('model_corecatalog_catalog')->setState('active', 1)->setState('lang', $this->getCurrentLangID())->setState('join.mainimage', true)->setState('only.withimages', true)->setState('lang', $this->getCurrentLangID());
             switch ($params->_get('type_show')) {
                 case 'last':
                     $model->setState('order by', 'cat_datecreated DESC');
                     break;
                 case 'showed':
                     $model->setState('order by', 'cat_showed DESC');
                     break;
             }
             $this->setVar('items', $model->getItems($this->_itemsperpage));
         } else {
             //special offers for menu
             $model = rad_instances::get('model_corecatalog_catalog')->setState('special_offer', $params->cs_type)->setState('limit', $params->itemsperpage)->setState('where_condition', ' 1 ')->setState('lang', $this->getCurrentLangID());
             if ($params->ordering !== 0) {
                 $model->setState('order by', $params->ordering);
             }
             $items = $model->getProductsList();
             model_corecatalog_currcalc::init();
             $curCurrency = model_corecatalog_currcalc::$_curcours;
             foreach ($items as &$item) {
                 if ($item->cat_currency_id != $curCurrency->cur_id) {
                     $item->cat_cost = model_corecatalog_currcalc::calcCours($item->cat_cost, $item->cat_currency_id);
                     $item->currency_indicate = $curCurrency->cur_ind;
                 }
             }
             $this->setVar('products', $items);
         }
     }
 }
Example #3
0
 public static function setDefaultCurrencyId($cur_id)
 {
     self::init();
     if (isset(self::$_currs[$cur_id])) {
         self::$_curcours = self::$_currs[$cur_id];
         $_SESSION['cur_default_site'] = $cur_id;
         $result = true;
     } else {
         $result = false;
     }
     return $result;
 }
Example #4
0
 /**
  * ReCalc referal order sum
  * @param integer $order
  * @return boolean
  */
 function recalcOrderSum($order)
 {
     $orderPositions = array();
     rad_instances::get('model_corecatalog_order')->assignPositions($orderPositions, $order);
     $orderSum = 0;
     if (!empty($orderPositions)) {
         foreach ($orderPositions as $id) {
             $orderSum += model_corecatalog_currcalc::calcCours($id->orp_cost, $id->orp_curid) * $id->orp_count;
         }
     }
     $this->query('UPDATE ' . RAD . 'referals_orders SET rro_order_sum=:order_sum WHERE rro_order_id=:order_id', array('order_sum' => $orderSum, 'order_id' => (int) $order));
     return true;
 }
Example #5
0
 function assignCurrency()
 {
     $items = rad_instances::get('model_corecatalog_currency')->getItems();
     $this->setVar('currency', $items);
     $this->setVar('currentCurrency', model_corecatalog_currcalc::getDefaultCurrencyId());
 }
Example #6
0
 /**
  * Final order!
  * return HTML to AJAX
  */
 function order()
 {
     $isNewUser = false;
     $item = new struct_corecatalog_orders();
     $item->order_userid = ($user = $this->getCurrentUser()) ? $user->u_id : 0;
     if ($this->_showCaptcha or $this->_OrderScheme[self::ORDER_REG]) {
         $captcha = new model_coresession_captcha(SITE_ALIAS);
         if (!$captcha->check($this->request('captcha_text'))) {
             $this->setVar('message', $this->lang('wrongcaptcha.session.error'));
             $this->startPage();
             $this->setVar('wrong_capcha', true);
             return;
         }
     }
     $item->order_address = $this->request('address', '');
     $item->order_comments = $this->request('order_comment');
     $item->order_email = $this->getCurrentUser()->u_email ?: $this->request('email');
     $item->order_fio = $this->request('fio');
     $item->order_phone = $this->request('contact_phone');
     $item->order_langid = $this->getCurrentLangID();
     if ($this->request('delivery')) {
         $item->order_delivery = (int) $this->request('delivery');
     }
     if ($item->order_userid === 0) {
         //type of the order - 3 is the quick order
         $item->order_type = 3;
         $isNewUser = true;
     } else {
         if ($this->_OrderScheme[self::ORDER_FAST_REG]) {
             //type of the order - 2 is the quick & registration
             $item->order_type = 2;
         } else {
             //type of the order - 1 is the registration
             $item->order_type = 1;
         }
     }
     $item->order_dt = now();
     $item->order_num = date("ymdHis");
     $item->order_num .= $this->getCurrentUser() ? 'u' . $this->getCurrentUser()->u_id : 's';
     $item->order_sessid = $this->getCurrentSessID();
     //Link to the tree_id
     $item->order_status = $this->_defStatus;
     //calc the order summ
     $model_bin = rad_instances::get('model_corecatalog_bin');
     $ct_showing = $this->getParamsObject() ? $this->getParamsObject()->ct_showing : NULL;
     $items = $model_bin->getCartProducts(NULL, NULL, $ct_showing);
     $bin_pos = $model_bin->getItemsCart();
     $counts = array();
     $bin_ids = array();
     $total_count = 0;
     $total_costs = 0;
     if (count($bin_pos)) {
         foreach ($bin_pos as $id) {
             $counts[$id->bp_catid] = $id->bp_count;
             $bin_ids[$id->bp_catid] = $id->bp_id;
         }
     }
     for ($i = 0; $i < count($items); $i++) {
         $items[$i]->cat_cost = model_corecatalog_currcalc::calcCours($items[$i]->cat_cost, $items[$i]->cat_currency_id);
         $items[$i]->cat_count = $counts[$items[$i]->cat_id];
         $total_count += $items[$i]->cat_count;
         $total_costs += $items[$i]->cat_cost * $items[$i]->cat_count;
         $items[$i]->bp_id = $bin_ids[$items[$i]->cat_id];
     }
     if ($this->_showDelivery and $this->request('delivery')) {
         $delivery = new struct_corecatalog_delivery(array('rdl_id' => (int) $this->request('delivery')));
         $delivery->load();
         $totalCostsWithoutDelivery = $total_costs;
         $total_costs += model_corecatalog_currcalc::calcCours($delivery->rdl_cost, $delivery->rdl_currency);
         $item->delivery = $delivery;
     }
     $item->order_summ = $total_costs;
     $item->order_currency = model_corecatalog_currcalc::$_curcours->cur_ind;
     $item->order_curid = model_corecatalog_currcalc::$_curcours->cur_id;
     if ($isNewUser && $this->_addtoclients) {
         //try, maybe user already exists
         $modelUsers = rad_instances::get('model_core_users');
         $exUser = $modelUsers->setState('u_email', $item->order_email)->getItem();
         if (!empty($exUser->u_id)) {
             $item->order_userid = (int) $exUser->u_id;
             $isNewUser = false;
         } else {
             $user = new struct_core_users(array('u_group' => $this->_clientsPID, 'u_login' => $item->order_email, 'u_email' => $item->order_email, 'u_fio' => $item->order_fio, 'u_phone' => $item->order_phone, 'u_address' => $item->order_address, 'u_isadmin' => 0));
             $modelUsers->register($user, $this->config('registration.class') != 'registerphpbb');
             $item->order_userid = $user->u_id;
         }
     }
     $model = rad_instances::get('model_corecatalog_order');
     if ($rows = $model->insertItem($item)) {
         $item->order_id = $rows;
         $item->order_num .= $item->order_id;
         $item->save();
         rad_instances::get('model_corecatalog_bin')->clearItemsCart();
         /*assign to the referals*/
         if ($this->config('referals.on') and class_exists('struct_coresession_referals_orders')) {
             //TODO Учесть что пользователь до этого уже приведен был другим партнером и взять с user_id
             if ($this->cookie($this->config('referals.cookieName')) or !empty($item->order_userid)) {
                 if ($item->order_userid !== 0) {
                     $refUser = rad_instances::get('model_coresession_referals')->getUserPartner($item->order_userid);
                 }
                 if (!empty($refUser->u_id)) {
                     $referalId = $refUser->rru_referal_id;
                 } elseif ($referal = rad_instances::get('model_coresession_referals')->setState('cookie', $this->cookie($this->config('referals.cookieName')))->getItem()) {
                     $referalId = $referal->rrf_id;
                 }
                 if (!empty($referalId)) {
                     $percent = rad_instances::get('model_coresession_referals')->getParntnerPercent($referalId);
                     $orderSum = isset($totalCostsWithoutDelivery) ? $totalCostsWithoutDelivery : $item->order_summ;
                     $refOfder = new struct_coresession_referals_orders(array('rro_referals_id' => $referalId, 'rro_order_id' => $item->order_id, 'rro_percent' => $percent, 'rro_currency_id' => $item->order_curid, 'rro_order_sum' => $orderSum));
                     rad_instances::get('model_coresession_referals')->insertOrder($refOfder);
                 }
             }
         }
     }
     $item->order_positions = $bin_pos;
     if ($isNewUser) {
         $this->_sendMail($item, 'order_new');
     } else {
         $this->_sendMail($item, 'order_new_auth');
     }
     $this->redirect($this->makeURL('action=success'));
 }
Example #7
0
 protected function assignFilterPrice()
 {
     if (empty($this->_catIds)) {
         $cats = $this->_getCatsProducts();
         if (!empty($cats)) {
             foreach ($cats as $id) {
                 $this->_catIds[] = $id['cat_id'];
             }
         }
     }
     if (!empty($this->_catIds)) {
         $minmax = rad_instances::get('model_corecatalog_catalog')->setState('currency', model_corecatalog_currcalc::getDefaultCurrencyId())->setState('active', 1)->setState('tre_id', (int) $this->request($this->_getcat))->getMinMaxPrices();
         $minmax['minprice'] = $minmax['minprice'] ? $minmax['minprice'] : 0;
         $minmax['maxprice'] = $minmax['maxprice'] ? $minmax['maxprice'] : 0;
         $this->setVar('prices', array('min' => $minmax['minprice'], 'max' => $minmax['maxprice']));
         $this->_current['costfrom'] = $this->request('costfrom', $minmax['minprice']);
         if ($this->request('costfrom')) {
             $this->_currentFilter .= '&costfrom=' . $this->request('costfrom', $minmax['minprice']);
         }
         $this->_current['costto'] = $this->request('costto', $minmax['maxprice']);
         if ($this->request('costto')) {
             $this->_currentFilter .= '&costto=' . $this->request('costto', $minmax['maxprice']);
         }
     }
 }
Example #8
0
 protected function changeCurrency()
 {
     if (model_corecatalog_currcalc::setDefaultCurrencyId((int) $this->request('cur_id'))) {
         echo 'location.reload();';
     }
 }
Example #9
0
 function __construct()
 {
     if ($this->getParamsObject()) {
         $params = $this->getParamsObject();
         $this->_showPages = $params->_get('showpages', $this->_showPages, $this->getCurrentLangID());
         $this->_treePages = $params->_get('treepages', $this->_treePages, $this->getCurrentLangID());
         $this->_showArticles = $params->_get('showarticles', $this->_showArticles, $this->getCurrentLangID());
         $this->_treeArticles = $params->_get('treearticles', $this->_treeArticles, $this->getCurrentLangID());
         $this->_showNews = $params->_get('shownews', $this->_showNews, $this->getCurrentLangID());
         $this->_treeNews = $params->_get('treenews', $this->_treeNews, $this->getCurrentLangID());
         $this->_showCatalog = $params->_get('showcatalog', $this->_showCatalog);
         $this->_treeCatalog = $params->_get('treecatalog', $this->_treeCatalog, $this->getCurrentLangID());
         $this->_exportSite = $params->_get('export', $this->_exportSite);
         $this->_shopName = $params->_get('shopname', $this->_shopName, $this->getCurrentLangID());
         $this->_shopCompany = $params->_get('shopcompany', $this->_shopCompany, $this->getCurrentLangID());
         $this->_shopAgency = $params->_get('shopagency', $this->_shopAgency, $this->getCurrentLangID());
         $this->setVar('params', $params);
     }
     switch ($this->_exportSite) {
         case 'sitemap':
             if ($this->_showPages) {
                 $pagesTree = rad_instances::get('model_coremenus_tree')->setState('active', 1)->setState('pid', $this->_treePages)->setState('lang', $this->getCurrentLangID())->getItems(true);
                 if (!empty($pagesTree)) {
                     rad_instances::get('model_corearticles_pages')->getPagesForTree($pagesTree, $this->getCurrentLangID());
                     $this->setVar('pagesTree', $pagesTree);
                 }
             }
             if ($this->_showArticles) {
                 $articlesTree = rad_instances::get('model_coremenus_tree')->setState('active', 1)->setState('pid', $this->_treeArticles)->setState('lang', $this->getCurrentLangID())->getItems(true);
                 if (!empty($articlesTree)) {
                     rad_instances::get('model_corearticles_articles')->getArticlessForTree($articlesTree, $this->getCurrentLangID());
                     $this->setVar('articlesTree', $articlesTree);
                 }
                 $this->setVar('articles', $articlesTree);
             }
             if ($this->_showNews) {
                 $newsTree = rad_instances::get('model_coremenus_tree')->setState('active', 1)->setState('pid', $this->_treeNews)->setState('lang', $this->getCurrentLangID())->getItems(true);
                 if (!empty($newsTree)) {
                     rad_instances::get('model_corearticles_news')->getNewsForTree($newsTree, $this->getCurrentLangID());
                     $this->setVar('newsTree', $newsTree);
                 }
             }
             //Show News
             if ($this->_showCatalog) {
                 $catalogTree = rad_instances::get('model_coremenus_tree')->setState('active', 1)->setState('pid', $this->_treeCatalog)->setState('lang', $this->getCurrentLangID())->getItems(true);
                 $modelCatalog = rad_instances::get('model_corecatalog_catalog')->setState('active', 1)->setState('join.mainimage', true)->setState('join.tree', true)->setState('lang', $this->getCurrentLangID())->setSTate('currency', model_corecatalog_currcalc::getDefaultCurrencyId());
                 $products = $modelCatalog->getItems();
                 if (!empty($products)) {
                     foreach ($products as $product) {
                         $this->_catRecursy($catalogTree, $product);
                     }
                 }
                 $this->setVar('catalog', $catalogTree);
             }
             break;
         case 'yandex.yml':
             header("Content-Type: text/xml");
             $this->setVar('nowdate', date("Y-m-d H:i"));
             $this->setVar('shop_name', mb_strlen($this->_shopName, 'utf-8') >= 20 ? mb_substr($this->_shopName, 0, 17, 'utf-8') . '...' : $this->_shopName);
             //Короткое название магазина — название, которое выводится в списке найденных на Яндекс. Маркете товаров. Оно не должно содержать более 20 символов.
             $this->setVar('shop_company', $this->_shopCompany);
             //Полное наименование компании, владеющей магазином. Не публикуется, используется для внутренней идентификации
             $this->setVar('shop_url', $this->config('url'));
             //URL главной страницы магазина.
             $this->setVar('shop_platform', 'Taberna');
             //CMS, на основе которой работает магазин.
             $this->setVar('shop_version', rad_update::getInstance()->getCurrentVersion());
             //Версия CMS.
             $this->setVar('shop_agency', $this->_shopAgency);
             //Наименование агентства, которое оказывает техническую поддержку магазину и отвечает за работоспособность сайта.
             $this->setVar('shop_email', $this->config('system.mail'));
             //Контактный адрес разработчиков CMS или агентства, осуществляющего техподдержку.
             //    Show currencies
             $currencies = rad_instances::get('model_corecatalog_currency')->getItems();
             $this->setVar('currencies', $currencies);
             //    Show categries & offers
             $this->setVar('showCatalog', $this->_showCatalog);
             if ($this->_showCatalog) {
                 $catalogTree = rad_instances::get('model_coremenus_tree')->setState('active', 1)->setState('pid', $this->_treeCatalog)->setState('lang', $this->getCurrentLangID())->getItems(true);
                 $modelCatalog = rad_instances::get('model_corecatalog_catalog')->setState('active', 1)->setState('join.mainimage', true)->setState('join.tree', true)->setState('lang', $this->getCurrentLangID())->setSTate('currency', model_corecatalog_currcalc::getDefaultCurrencyId());
                 $products = $modelCatalog->getItems();
                 if (!empty($products)) {
                     $modelCatalog->getValValues($products);
                     foreach ($products as $product) {
                         //    Params
                         if (count($product->type_vl_link)) {
                             foreach ($product->type_vl_link as $tvlkey => $tvl) {
                                 if ($product->type_vl_link[$tvlkey]->vl_measurement_id) {
                                     $mesId = $product->type_vl_link[$tvlkey]->vl_measurement_id;
                                     $mes = new struct_corecatalog_measurement(array('ms_id' => $mesId));
                                     $mes->load();
                                     $product->type_vl_link[$tvlkey]->ms_value = trim($mes->ms_value);
                                 }
                             }
                         }
                         //    Pictures
                         $model_images = rad_instances::get('model_core_image');
                         $model_images->setState('cat_id', $product->cat_id);
                         $product->images_link = $model_images->getItems();
                         //    Name
                         if (mb_strlen($product->cat_name, 'utf-8') >= 255) {
                             $product->cat_shortdesc = mb_substr($product->cat_name, 0, 252, 'utf-8') . '...';
                         }
                         //    Desctiption
                         $product->cat_shortdesc = strip_tags($product->cat_shortdesc);
                         if (mb_strlen($product->cat_shortdesc, 'utf-8') >= 512) {
                             $product->cat_shortdesc = mb_substr($product->cat_shortdesc, 0, 509, 'utf-8') . '...';
                         }
                         $this->_catRecursy($catalogTree, $product);
                     }
                 }
                 $this->setVar('catalog', $catalogTree);
             }
     }
 }
Example #10
0
 /**
  * Shows the edit order form of just a view
  *
  */
 function showEdit()
 {
     $order_id = (int) $this->request('oid');
     if ($order_id) {
         $this->setVar('order_id', $order_id);
         $model = rad_instances::get('model_corecatalog_order');
         $order = $model->getItem($order_id, true);
         if ($order->order_delivery) {
             $order->delivery = new struct_corecatalog_delivery(array('rdl_id' => $order->order_delivery));
             $order->delivery->load();
         }
         $this->setVar('order', $order);
         $this->addBC('cur_order_num', $order->order_num);
         $total_count = 0;
         $total_cost = 0;
         if (count($order->order_positions)) {
             foreach ($order->order_positions as $id) {
                 $total_count += $id->orp_count;
                 $total_cost += $id->orp_count * model_corecatalog_currcalc::calcCours($id->orp_cost, $id->orp_curid);
             }
             //foreach
         }
         //if count
         $this->setVar('total_cost', $total_cost);
         $this->setVar('total_count', $total_count);
         $this->setVar('currency', model_corecatalog_currcalc::$_curcours);
         $this->assignTypes();
     } else {
         $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName());
     }
 }
Example #11
0
 /**
  * Special for search
  * @todo JOIN the main image!
  */
 function searchItems($searchword = '', $ct_showing = 0)
 {
     $q = new rad_query();
     $withvals = $this->getState('withvals');
     $where_like = array();
     $limit = $this->getState('limit', '0,20');
     $limit = ' LIMIT ' . $limit;
     $order = $this->getState('order by', 'cat_position, cat_name, cat_datecreated, cat_usercreated');
     $order = ' ORDER BY ' . $order . ' ';
     if ($this->getState('count')) {
         $q->select('count(c.cat_id)');
     } elseif ($withvals) {
         $q->select('c.*, tps.*, i.img_filename as img_filename');
     } else {
         $q->select('c.*, i.img_filename as img_filename');
     }
     $q->from(RAD . 'cat_val_values vl ');
     $q->join('INNER', RAD . 'cat_val_names vn ON vl.vv_name_id = vn.vl_id');
     $q->join('INNER', RAD . 'catalog c ON c.cat_id = vl.vv_cat_id AND c.cat_ct_id = vn.vl_tre_id');
     $q->join('INNER', RAD . 'tree tps ON tps.tre_id = c.cat_ct_id');
     $q->join('LEFT', RAD . 'cat_images i on img_cat_id=cat_id and img_main=1');
     $cat_in_tree = $this->getState('cat_in_tre');
     if ($cat_in_tree) {
         $q->join('LEFT', RAD . 'cat_in_tree cit ON cit.cit_cat_id = c.cat_id');
         if (is_array($cat_in_tree) and count($cat_in_tree)) {
             $where = ' WHERE cit.cit_tre_id in (' . implode(',', $cat_in_tree) . ') ';
         } else {
             $where = ' WHERE cit.cit_tre_id="' . (int) $cat_in_tree . '" ';
         }
     } else {
         $where = ' WHERE 1';
     }
     if ($this->getState('active', 2) == 1 or $this->getState('active', 2) == 0) {
         $where .= ' and cat_active=' . $this->getState('active');
     }
     if ($this->getState('with_vv', true)) {
         $where_like[] = '(vl.vv_value LIKE "%' . $searchword . '%")';
         $where_like[] = '(vl.vv_value2 LIKE "%' . $searchword . '%") ';
     }
     if ($this->getState('with_cat_name', true)) {
         $where_like[] = '(c.cat_name LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_fulldesc', true)) {
         $where_like[] = '(c.cat_fulldesc LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_shortdesc', true)) {
         $where_like[] = '(c.cat_shortdesc LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_article', true)) {
         $where_like[] = '(c.cat_article LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_code', true)) {
         $where_like[] = '(c.cat_code LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_keywords', true)) {
         $where_like[] = '(c.cat_keywords LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_metatitle', true)) {
         $where_like[] = '(c.cat_metatitle LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_cat_metatescription', true)) {
         $where_like[] = '(c.cat_metatescription LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_vl_name', true)) {
         $where_like[] = '(vn.vl_name LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('with_tre_name', true)) {
         $q->join('LEFT', RAD . 'tree t on t.tre_id = cit.cit_tre_id ');
         $where_like[] = '(t.tre_name LIKE "%' . $searchword . '%")';
     }
     if ($this->getState('lang')) {
         $where .= ' and c.cat_lngid=' . (int) $this->getState('lang') . ' ';
     }
     if ($this->getState('cost_from') or $this->getState('cost_to')) {
         $q->join('LEFT', RAD . 'currency cr on cat_currency_id=cur_id');
         $where .= ' and ( ( c.cat_cost*(cr.cur_cost/' . model_corecatalog_currcalc::currCours() . ')>=' . (int) $this->getState('cost_from') . ') ';
         if ((int) $this->getState('cost_to') > 0) {
             $where .= ' and ( c.cat_cost*(cr.cur_cost/' . model_corecatalog_currcalc::currCours() . ')<=' . (int) $this->getState('cost_to') . ')';
         }
         $where .= ' ) ';
     }
     $sql = $q->toString() . $where . ' AND (' . implode(' or ', $where_like) . ') ' . ' GROUP BY c.cat_id ' . $order . $limit;
     $result = array();
     if ($this->getState('count')) {
         $result = $this->queryAll($sql);
         $result = count($result);
     } else {
         foreach ($this->queryAll($sql) as $id) {
             $result[] = new struct_corecatalog_catalog($id);
             if ($withvals) {
                 $result[count($result) - 1]->type_link = new struct_coremenus_tree($id);
             }
         }
         if ($withvals and $ct_showing) {
             $this->getValValues($result, $ct_showing);
         }
     }
     return $result;
 }
Example #12
0
 function changePositionCount($order_id, $cat_id, $count)
 {
     $order = $this->getItem($order_id, true);
     if (!empty($order->order_positions)) {
         $pos_id = 0;
         foreach ($order->order_positions as $orpos) {
             $orpos->orp_catid = (int) $orpos->orp_catid;
             if ($orpos->orp_catid === $cat_id) {
                 $pos_id = (int) $orpos->orp_id;
                 break;
             }
         }
         if ($pos_id > 0) {
             $position = new struct_corecatalog_order_positions(array('orp_id' => $pos_id));
             $position->load();
             if ((double) $position->orp_count != $count) {
                 $model_catalog = rad_instances::get('model_corecatalog_catalog');
                 $model_catalog->setState('with_vv', true);
                 $product = $model_catalog->getItem($cat_id);
                 $pos_summ = (double) $position->orp_count * (double) $position->orp_cost;
                 $new_pos_summ = $count * (double) $product->cat_cost;
                 $new_pos_summ = model_corecatalog_currcalc::calcCours($new_pos_summ, $order->order_curid);
                 $order->order_summ = $order->order_summ - ($pos_summ - $new_pos_summ);
                 $position->orp_count = '' . $count;
                 $this->updateItem($order);
                 return $position->save();
             }
         }
     }
     return 0;
 }
Example #13
0
 /**
  * Shows a bin window at goods addition
  *
  */
 function showBinWindow()
 {
     model_corecatalog_currcalc::init();
     $this->setVar('curr', model_corecatalog_currcalc::$_curcours);
     $model = rad_instances::get('model_corecatalog_bin');
     $ct_showing = $this->getParamsObject() ? $this->getParamsObject()->ct_showing : NULL;
     $items = $model->getCartProducts(NULL, NULL, $ct_showing);
     $bin_pos = $model->getItemsCart();
     $counts = array();
     $bin_ids = array();
     $total_count = 0;
     $total_costs = 0;
     if (count($bin_pos)) {
         foreach ($bin_pos as $id) {
             $counts[$id->bp_catid] = $id->bp_count;
             $bin_ids[$id->bp_catid] = $id->bp_id;
         }
     }
     for ($i = 0; $i < count($items); $i++) {
         $items[$i]->cost = $items[$i]->cat_cost;
         $items[$i]->cat_cost = model_corecatalog_currcalc::calcCours($items[$i]->cat_cost, $items[$i]->cat_currency_id);
         $items[$i]->cat_count = $counts[$items[$i]->cat_id];
         $total_count += $items[$i]->cat_count;
         $total_costs += $items[$i]->cat_cost * $items[$i]->cat_count;
         $items[$i]->bp_id = $bin_ids[$items[$i]->cat_id];
     }
     $this->setVar('items', $items);
     $this->setVar('total_count', $total_count);
     $this->setVar('total_costs', $total_costs);
 }
Example #14
0
 /**
  * Assign the products
  */
 function assignProducts()
 {
     $cat = (int) $this->request('cat', $this->_pid);
     $special_offer = (int) $this->request('so');
     $order_by = $this->request('o');
     $order_by_asc = (int) $this->request('asc', 2);
     if (!$cat and !$special_offer) {
         $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName());
         return;
     }
     $this->setVar('itemsPerPageDefault', $this->_itemsPerPage);
     $this->_itemsPerPage = (int) $this->request('i', $this->_itemsPerPage);
     $this->setVar('itemsPerPage', $this->_itemsPerPage);
     $model = rad_instances::get('model_corecatalog_catalog');
     if (!$special_offer) {
         $this->setVar('cat_id', $cat);
         $model->setState('tre_id', $cat);
         $tree_item = rad_instances::get('model_coremenus_tree')->getItem($cat);
         $this->setVar('tree_item', $tree_item);
     } else {
         $this->setVar('special_offer', $special_offer);
         $model->setState('special_offer', $special_offer);
         $model->setState('where_condition', ' 1 ');
         $this->addBC('so_id', $special_offer);
         $this->addBC('so_name', $this->lang('specialoffer' . $special_offer . '.catalog.title'));
     }
     $model->setState('active', 1);
     $model->setState('lang', $this->getCurrentLangID());
     if ($this->request('filter')) {
         if ((int) $this->request('brand_id')) {
             if (strstr($this->request('brand_id'), ',')) {
                 $brands = explode(',', $this->request('brand_id'));
                 foreach ($brands as $keyBrand => $valBrand) {
                     if (!(int) $valBrand) {
                         unset($brands[$keyBrand]);
                     }
                     //if
                 }
                 //foreach
             } else {
                 $brands = $this->request('brand_id', 0);
             }
             $model->setState('brand_id', $brands);
             $this->_currentFilter['brand_id'] = $brands;
         }
         if ($this->request('vv')) {
             $vv = array();
             foreach ($this->request('vv') as $vlNameId => $vvValue) {
                 if (!empty($vvValue)) {
                     $vv[$vlNameId] = $vvValue;
                 }
             }
             if (!empty($vv)) {
                 $model->setState('val_values', $vv);
                 $this->_currentFilter['vv'] = $vv;
             }
         }
         if ((double) $this->request('costfrom')) {
             $model->setState('cost.from', (double) $this->request('costfrom'));
             $this->_currentFilter['costfrom'] = (double) $this->request('costfrom');
             $model->setState('currency', model_corecatalog_currcalc::getDefaultCurrencyId());
         }
         if ((double) $this->request('costto')) {
             $model->setState('cost.to', (double) $this->request('costto'));
             $this->_currentFilter['costto'] = (double) $this->request('costto');
             $model->setState('currency', model_corecatalog_currcalc::getDefaultCurrencyId());
         }
     }
     $products_count = $model->getProductsListCount();
     $this->setVar('products_count', $products_count);
     $p = (int) $this->request('p');
     $page = $p ? $p : 0;
     $limit = $page * $this->_itemsPerPage . ',' . $this->_itemsPerPage;
     $model->setState('limit', $limit);
     $order = ' c.cat_position, ';
     switch ($this->request('o')) {
         case 'name':
             $order .= 'c.cat_name';
             break;
         case 'cost':
             $order .= 'c.cat_cost*(cr.cur_cost/' . model_corecatalog_currcalc::currCours() . ')';
             break;
         default:
             $order .= 'c.cat_name';
             break;
     }
     $order .= $this->request('asc', true) ? ' ASC' : ' DESC';
     $model->setState('order by', $order);
     $products = $model->getProductsList(true, $this->_ct_showing);
     if ($products_count) {
         $pages = div((int) $products_count, $this->_itemsPerPage);
         $pages += $products_count % $this->_itemsPerPage ? 1 : 0;
         $this->setVar('pages_count', $pages + 1);
         $this->setVar('page', $page + 1);
         $this->setVar('currPage', (int) $this->request('p', $page));
     } else {
         $this->setVar('pages_count', 0);
         $this->setVar('page', 1);
         $this->setVar('currPage', (int) $this->request('p', 0));
     }
     foreach ($products as $pkey => $product) {
         if (count($product->type_vl_link)) {
             foreach ($product->type_vl_link as $tvlkey => $tvl) {
                 if ($product->type_vl_link[$tvlkey]->vl_measurement_id) {
                     $mes_id = $product->type_vl_link[$tvlkey]->vl_measurement_id;
                     $mes = new struct_corecatalog_measurement(array('ms_id' => $mes_id));
                     $mes->load();
                     $products[$pkey]->type_vl_link[$tvlkey]->ms_value = $mes->ms_value;
                 }
             }
         }
         if ($this->config('partners.3dbin.license')) {
             rad_instances::get('model_corecatalog_3dimages')->assign3Dimages($products);
         }
     }
     $this->setVar('products', $products);
 }