Exemplo n.º 1
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;
 }
Exemplo n.º 2
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);
 }