pecial ";$poles.=($this->date_end)?",(SELECT ps2.`date_end` FROM `".DB_PREFIX."product_special` ps2 WHERE ps2.`product_id`=p.`product_id` AND((ps2.`date_start`='0000-00-00' OR ps2.`date_start`<'".$this->today."')AND(ps2.`date_end`='0000-00-00' OR ps2.`date_end`>'".$this->today."'))ORDER BY ps2.`priority` ASC,ps2.`price` ASC LIMIT 1)AS date_end ":null;}$poles.=($this->stock_status)?",(SELECT ss.`name` FROM `".DB_PREFIX."stock_status` ss WHERE ss.`stock_status_id`=p.`stock_status_id` AND ss.`language_id`=".$this->language_id." LIMIT 1)AS stock_status ":",p.`stock_status_id` AS stock_status ";$poles.=($this->discount)?",(SELECT pd2.`price` FROM `".DB_PREFIX."product_discount` pd2 WHERE pd2.`product_id`=p.`product_id` AND pd2.`customer_group_id`=".$this->customer_group_id." AND pd2.`quantity`='1' AND((pd2.`date_start`='0000-00-00' OR pd2.`date_start`<'".$this->today."')AND(pd2.`date_end`='0000-00-00' OR pd2.`date_end`>'".$this->today."'))ORDER BY pd2.`priority` ASC,pd2.`price` ASC LIMIT 1)AS discount ":null;$poles.=($this->mini_description)?",CONCAT(LEFT(pd.`description`,100),'...')AS mini_description ":null;$poles.=($this->reward)?",(SELECT `points` FROM `".DB_PREFIX."product_reward` pr WHERE pr.`product_id`=p.`product_id` AND `customer_group_id`=".$this->customer_group_id." LIMIT 1)AS reward ":null;foreach($this->genQueryStr($arr_sql)as $k_=>$v_){${$k_}.=$v_;}$sql.=" JOIN `".DB_PREFIX."product_description` pd ON(p.`product_id`=pd.`product_id`)";$sql.=" LEFT JOIN `".DB_PREFIX."review` AS r ON(p.`product_id`=r.`product_id`)";if($this->manufacturer){$poles.=",m.`name` AS manufacturer ";$sql.=" LEFT JOIN `".DB_PREFIX."manufacturer` m ON(p.`manufacturer_id`=m.`manufacturer_id`)";}if($this->mult_store){$sql.=" RIGHT JOIN `".DB_PREFIX."manufacturer_to_store` m2s ON(p.`manufacturer_id`=m2s.`manufacturer_id`)";}if(isset($arr_sql['start'])|| isset($arr_sql['limit'])){if((int)$arr_sql['start']<0){$arr_sql['start']=0;}if((int)$arr_sql['limit']<1){$arr_sql['limit']=20;}$limit.=" LIMIT ".(int)$arr_sql['start'].",".(int)$arr_sql['limit'];}$sort_data=array('pd.name','p.model','p.quantity','p'.$this->prs_spec.'.price','rating','p.sort_order','p.date_added');$sort_order=array('ASC','DESC','asc','desc');if(isset($arr_sql['order'])&&in_array($arr_sql['order'],$sort_order)){$sort=' '.$arr_sql['order'].' ';}if(isset($arr_sql['sort'])&&in_array($arr_sql['sort'],$sort_data)){if(($arr_sql['sort']=='pd.name')||($arr_sql['sort']=='p.model')){$order=" LCASE(".$arr_sql['sort'].")";}elseif($arr_sql['sort']=='p'.$this->prs_spec.'.price'){$order=" ".$this->pole_price_sort." ";}elseif(($arr_sql['sort']=='rating')){$order=" p.`viewed` ";}else{$sorts=null;if(isset($this->set_mod['sort_default'])){$sort_default=$this->set_mod['sort_default'];$arr_sorts=array("sort_name"=>"LCASE(pd.`name`)","sort_model"=>"LCASE(p.`model`)","sort_price"=>$this->pole_price_sort,"sort_price_desc"=>$this->pole_price_sort." DESC","sort_rating_desc"=>"r.`rating` DESC","sort_viewed_desc"=>"p.`viewed` DESC","sort_date_added_desc"=>"p.`date_added` DESC","sort_quantity_desc"=>"p.`quantity` DESC");if(isset($arr_sorts[$sort_default])){$sorts=$arr_sorts[$sort_default];}}if($sorts){$sort=null;$order=' '.$sorts.' ';}else{$order=' '.$arr_sql['sort'].' ';}}}else{$order=" p".$this->prs_spec.".`sort_order` ";}$sort_quanty_before=null;if($this->sort_quantity){$sort_quanty_before=" ".$this->text_where_product." DESC,";}foreach($this->genGetParam($get_param,false)as $key=>$val){${$key}.=$val;}if($where){$where.=" AND pd.`language_id`=".$this->language_id." ";}$order_by=" ORDER BY ".$sort_quanty_before.$order.$sort;$query_str="SELECT SQL_CALC_FOUND_ROWS ".$poles." FROM ".$sql.$where.$group_by.$having.$order_by.$limit;$query=$this->db->query($query_str);return $query->rows;}public function getTotalProducts(){$count_query=$this->db->query("SELECT FOUND_ROWS()AS total");$this->total_products=(int)$count_query->row['total'];return $this->total_products;}private function genQueryStr($arr_sql=array()){$sql=null;$poles=null;$where=null;$group_by=null;$sql.=" `".DB_PREFIX."product` p ";if($this->prs_spec){$sql.=$this->sql_prs_spec;}else{$sql.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`".$this->and_group_id.")";}$group_by.=" p".$this->prs_spec.".`product_id` ";$poles.=",".$this->pole_pr_final." AS ".$this->pole_price_sort." ";if(!empty($arr_sql['filter_category_id'])){if($this->sub_cats){$cat_arr=$this->{'whereSubCats'.$this->cache_fv}($arr_sql['filter_category_id']);$where.=" WHERE ".$cat_arr." ";}else{if($arr_sql['filter_category_id']!==true){$where.=" WHERE p2c.`category_id`=".(int)$arr_sql['filter_category_id']." ";}}}$result=array('sql'=>$sql,'poles'=>$poles,'where'=>$where,'group_by'=>$group_by);return $result;}private function genGetParam($get_param=array(),$pole_date_new=false){$sql=null;$poles=null;$where=null;$set_mod=$this->set_mod;if($this->manufacturer_id){$where.=" WHERE p.`manufacturer_id`=".$this->manufacturer_id." ";}elseif($this->prs_spec){$where.=" WHERE ".$this->polePriceSpecial()." ";}else{$sql.=" JOIN `".DB_PREFIX."product_to_category` p2c ON(p.`product_id`=p2c.`product_id`)";}$manuf_text='manufs';$arr_manuf=array();if(isset($get_param[$manuf_text])){$arr_manuf=$get_param[$manuf_text];$arr_temp_id=array();foreach($arr_manuf as $key=>$arr_val){$arr_temp_id=$arr_val;}$where.=$this->whereImplode("p.`manufacturer_id`",$arr_temp_id);}$href_text='attrb';if(isset($get_param[$href_text])){$sql.=" JOIN `".DB_PREFIX."attribute_filter_vier` afv ON(p.`product_id`=afv.`product_id`)";$pole_text="afv.`attr_text`";$set_attr=$set_mod[$href_text];$arr_get=$get_param[$href_text];$flag_in_out=(isset($set_attr['inout']))?true:false;$key_id_first=false;$group_id_inout=false;$groups=array();$flag_first_count_group=false;$group_view=array();$is_group=false;$arr_inout=$this->model_module_filter_vier->processAttrGroup($arr_get);foreach($arr_inout as $k_io=>$v_io){${$k_io}=$v_io;}if(isset($set_attr['group_view'])){$group_view=$set_attr['group_view'];$is_group=(isset($group_view[$group_id_inout]))?true:false;}$arr_temp_text=array();$arr_tmp_text1=array();$arr_temp_id=array();$arr_temp_id2=array();$arr_tmp_text3=array();$arr_tmp_slider=array();$i=0;$for_sl=0;foreach($arr_get as $key=>$arr_val){$main_id=(int)$key;if(isset($set_attr['slider'][$main_id])){$arr_tmp_slider[$main_id]=$arr_val;continue;}foreach($arr_val as $v_){$text_id=(int)$v_;$text=$main_id.'_'.$text_id;$where_text=" ".$pole_text."='".$text."' ";if($flag_in_out){if((($main_id==$key_id_first))||((isset($attr_group[$main_id])&&($attr_group[$main_id]==$group_id_inout))&&$is_group)){$arr_tmp_text1[]="'".$text."'";}else{if(!empty($group_view)&&(isset($attr_group[$main_id])&&in_array(($gr=$attr_group[$main_id]),$group_view))){$arr_tmp_text3[$gr][$main_id]["'".$text."'"]="'".$text."'";}else{$arr_temp_id2[$main_id][]="'".$text."'";}}}else{if($i===0){$arr_temp_text[]=" AND ".$where_text." ";}else{$arr_temp_text[]=" AND afv.`product_id` IN(SELECT afv.`product_id` FROM `".DB_PREFIX."attribute_filter_vier` afv WHERE ".$where_text.")";}$i++;}$for_sl++;}}if(!empty($arr_tmp_text1)){$where.=$this->whereImplode($pole_text,$arr_tmp_text1);}if(!empty($arr_tmp_text3)){$temp_where=array();foreach($arr_tmp_text3 as $gr=>$arr_main){$arr_text=array();$arr_main_id=array_keys($arr_main);foreach($arr_main as $v){$arr_text[]=key($v);}$temp_where[]=" afv.`product_id` IN(SELECT afv.`product_id` FROM `".DB_PREFIX."attribute_filter_vier` afv WHERE ".$this->whereImplode($pole_text,$arr_text,null).")";}if(!empty($temp_where)){$where.=" AND ".implode(' AND ',$temp_where)." ";}}if(!empty($arr_temp_id2)){$temp_where=array();foreach($arr_temp_id2 as $main_id=>$arr_text){$temp_where[]=" afv.`product_id` IN(SELECT afv.`product_id` FROM `".DB_PREFIX."attribute_filter_vier` afv WHERE ".$this->whereImplode($pole_text,$arr_text,null).")";}if(!empty($temp_where)){$where.=" AND ".implode(' AND ',$temp_where)." ";}}if(!empty($arr_temp_text)){$where.=" ".implode(' ',$arr_temp_text)." ";}if(!empty($arr_tmp_slider)){$temp_where=array();foreach($arr_tmp_slider as $main_id=>$arr_val){$temp_where[]=$this->sqlAttrSlider($main_id,$arr_val,$for_sl);$for_sl++;}$where.=" ".implode(' ',$temp_where)." ";}}$option_text='optv';if(isset($get_param[$option_text])){$sql.=" LEFT JOIN `".DB_PREFIX."product_option_value` pov ON(p.`product_id`=pov.`product_id`)";$where.=" AND(pov.`quantity`>0)";$set_=$set_mod[$option_text];$arr_get=$get_param[$option_text];$keys_param=array_keys($arr_get);$key_id_first=(int)$keys_param[0];$flag_in_out=(isset($set_['inout']))?true:false;$arr_temp=array();$arr_o1=array();$arr_temp1=array();$arr_temp_id2=array();$i=0;foreach($arr_get as $key=>$arr_val){$main_id=(int)$key;foreach($arr_val as $v_){$v_=(int)$v_;if($flag_in_out){if($key===$key_id_first){$arr_o1[$main_id]=$main_id;$arr_temp1[]=$v_;}else{$arr_temp_id2[$main_id][]=$v_;}}else{if($i===0){$arr_temp[]=" AND pov.`option_value_id`=".$v_." ";}else{$arr_temp[]=" AND pov.`product_id` IN(SELECT pov.`product_id` FROM `".DB_PREFIX."product_option_value` pov WHERE pov.`option_value_id`=".$v_.")";}$i++;}}}if(!empty($arr_o1)){$where.=$this->whereImplode("pov.`option_id`",$arr_o1);$where.=$this->whereImplode("pov.`option_value_id`",$arr_temp1);}if(!empty($arr_temp_id2)){$temp_where=array();foreach($arr_temp_id2 as $main_id=>$arr_text){$temp_where[]=" pov.`product_id` IN(SELECT pov.`product_id` FROM `".DB_PREFIX."product_option_value` pov WHERE pov.`option_id` IN(".$main_id.")".$this->whereImplode("pov.`option_value_id`",$arr_text).")";}if(!empty($temp_where)){$where.=" AND ".implode(' AND ',$temp_where)." ";}}if(!empty($arr_temp)){$where.=" ".implode(" ",$arr_temp)." ";}}$price_text='prs';if(isset($get_param[$price_text])){$arr_price=$this->genQueryPrice($get_param[$price_text]);if(!empty($arr_price)){if($arr_price[0]==$arr_price[1]){$where.=" AND p".$this->prs_spec.".`price`=".$arr_price[0]." ";}else{$where.=" AND ".$this->pole_pr_final." BETWEEN ".$arr_price[0]." AND ".$arr_price[1]." ";}}}$quantity_text='qnts';if(isset($get_param[$quantity_text])){$where.=" AND(p.`quantity`>0)";}$nows_text='nows';$temp_sql_nows=null;if(isset($set_mod[$nows_text]['status'])&&$this->count_day){$temp_sql_nows=$this->sqlNows();if($pole_date_new){$poles.=",IF(".$temp_sql_nows.",1,0)AS date_new";}}if(!empty($this->count_day)&&!empty($temp_sql_nows)){if(isset($get_param[$nows_text])){$where.=" AND ".$temp_sql_nows." ";}}$where.=$this->paramPsp();if($this->mult_store){$sql.=" LEFT JOIN `".DB_PREFIX."product_to_store` p2s ON(p.`product_id`=p2s.`product_id`)";$where.=" AND p2s.store_id=".$this->store_id;}$where.=" AND p.`status`=1 ".$this->qnts_quant." ";$product_series=$this->productSeries();$sql.=$product_series['sql'];$where.=$product_series['where'];$result=array('sql'=>$sql,'poles'=>$poles,'where'=>$where);return $result;}private function paramPsp(){$where=null;if($this->akci_tov){$where.=" AND ".$this->polePriceSpecial()." ";}return $where;}public function whereImplode($pole,$arr=array(),$and='AND',$not=null){$result=null;if(!empty($arr)){$arr=array_unique($arr);asort($arr);$result=" ".$and." ".$pole." ".$not." IN(".implode(',',$arr).")";}return $result;}public function getProductsFilter_($arr_sql=array(),$flag_price=false){$key_cache=$this->genCacheProduct($arr_sql,$this->language_id.$this->akci_tov);$result=($flag_price)?false:$this->cache->get($key_cache);if(!$result){$result=$this->getProductsFilter($arr_sql,$flag_price);$this->cache->set($key_cache,$result);}return $result;}public function getProductsFilter($arr_sql=array(),$flag_price=false){$result=array();$get_param=$arr_sql['get_param'];$sql=null;$where=null;$order_by=null;$group_by=" GROUP BY ";$poles=" p.`product_id`,p.`manufacturer_id`,IF(p.`quantity`>0,1,0)AS quantity_new ";$poles.=",IF(".$this->polePriceSpecial().",1,0)AS special ";foreach($this->genQueryStr($arr_sql)as $k_=>$v_){${$k_}.=$v_;}foreach($this->genGetParam($get_param,true)as $key=>$val){${$key}.=$val;}if($flag_price){$poles=" MIN(".$this->pole_pr_final.")AS price_min,MAX(".$this->pole_pr_final.")AS price_max ";$group_by=null;}$query_str="SELECT ".$poles." FROM ".$sql." ".$where." ".$group_by." ".$order_by." ";$query=$this->db->query($query_str);if($flag_price){$result=$query->row;}else{$result=$query->rows;}return $result;}public function getCategorysFilter_($language_id,$sort_name=null,$flag_tec_count=false){$param='cats';$key_cache=$this->genCacheParam($param.'.'.$language_id,$sort_name.$flag_tec_count);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getCategorysFilter($language_id,$sort_name,$flag_tec_count);$this->cache->set($key_cache,$result);}return $result;}public function getCategorysFilter($language_id,$sort_name=null,$flag_tec_count=false){$poles=" c.`parent_id`,c.`category_id`,cd.`name`,c.`sort_order` ";$poles.=($flag_tec_count)?",COUNT(p2c.`category_id`)AS total ":null;$where=null;$group_by=null;$order_by=null;$query_str="SELECT ".$poles." FROM `".DB_PREFIX."category` c ";$query_str.=" LEFT JOIN `".DB_PREFIX."category_description` cd ON(c.`category_id`=cd.`category_id`)";$query_str.=" LEFT JOIN `".DB_PREFIX."product_to_category` p2c ON(c.`category_id`=p2c.`category_id`)";$query_str.=" LEFT JOIN `".DB_PREFIX."product` p ON(p2c.`product_id`=p.`product_id`)";$where.=" WHERE c.`status`=1 ";$where.=" AND p.`status`=1 ";$where.=" AND cd.`language_id`=".$language_id." ";$group_by.=" GROUP BY p2c.`category_id` ";$new_sort="c.`sort_order`,cd.`name`";if(!empty($sort_name)){$new_sort="cd.`name`";}$order_by.=" ORDER BY ".$new_sort." ASC ";$query_str.=$where.$group_by.$order_by;$query=$this->db->query($query_str);return $query->rows;}public function whereSubCats_($main_category){$param='cats_parent.'.(int)$main_category;$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->whereSubCats($main_category);$this->cache->set($key_cache,$result);}return $result;}public function whereSubCats($main_category){$where=null;if(!empty($main_category)){$implode_data=array();$implode_data[]=(int)$main_category;$categories=$this->getCategoriesByParentId($main_category);foreach($categories as $category_id){$implode_data[]=(int)$category_id;}$where.=$this->whereImplode('p2c.`category_id`',$implode_data,null);}return $where;}public function getCategoriesByParentId($category_id){$category_data=array();$categories=$this->getCategorys((int)$category_id);foreach($categories as $category){$category_data[]=$category['category_id'];$children=$this->getCategoriesByParentId($category['category_id']);if($children){$category_data=array_merge($children,$category_data);}}return $category_data;}private function getCategorys($id=0){static $rez=null;$poles="c.`category_id`,c.`parent_id`";if($rez===null){$rez=array();$query_str="SELECT ".$poles." FROM `".DB_PREFIX."category` c";$query_str.=" LEFT JOIN `".DB_PREFIX."category_to_store` c2s ON(c.`category_id`=c2s.`category_id`)";$query_str.=" WHERE c.`status`=1 ";$query_str.=" AND c2s.`store_id`=".$this->store_id." ";$query=$this->db->query($query_str);foreach($query->rows as $row){$rez[$row['parent_id']][]=$row;}}return(isset($rez[$id])?$rez[$id]:array());}public function getPrices_($where_category=null,$flag_min_max){$flag=($flag_min_max)?'.min_max':null;$param='prs'.$flag;$key_cache=$this->genCacheParam($param,$where_category.$this->akci_tov);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getPrices($where_category,$flag_min_max);$this->cache->set($key_cache,$result);}return $result;}public function getPrices($where_category,$flag_min_max){$result=array();$group_by=null;$order_by=null;if($flag_min_max){$poles=" MIN(".$this->pole_pr_final.")AS price_min,MAX(".$this->pole_pr_final.")AS price_max ";}else{$poles=" ".$this->pole_pr_final." AS ".$this->pole_price_sort." ";if(!$this->prs_count){$group_by=" GROUP BY ".$this->pole_price_sort." ";}$poles.=",p.`product_id`";$order_by=" ORDER BY ".$this->pole_price_sort." ASC ";}$where=" WHERE ".$where_category." ".$this->qnts_quant." ";$query_str="SELECT ".$poles." FROM `".DB_PREFIX."product` p ";if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{$query_str.=($this->manufacturer_id)?null:" JOIN `".DB_PREFIX."product_to_category` p2c USE INDEX(PRIMARY)USING(`product_id`)";$query_str.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`".$this->and_group_id.")";$where.=$this->paramPsp();}$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=" ".$group_by." ";$query_str.=" ".$order_by." ";$query=$this->db->query($query_str);if($flag_min_max){$result=$query->row;}else{$result=$query->rows;}return $result;}public function polePriceFinal(){if($this->special&&!$this->prs_spec){$result="IF(".$this->polePriceSpecial().",ps.`price`,p.`price`)";}else{$result="p".$this->prs_spec.".`price`";}return $result;}public function polePriceSpecial(){return "((ps.`date_start`='0000-00-00' OR ps.`date_start`<='".$this->today."')AND(ps.`date_end`='0000-00-00' OR ps.`date_end`>='".$this->today."')AND(ps.`customer_group_id`=".$this->customer_group_id."))";}public function allowancePrice($decimal_tec,$type=0){$allowance=$this->allowanceStr($decimal_tec);$result=((0.499999-$type)*($allowance));return $result;}public function allowanceStr($decimal_tec){$allowance=pow(10,$decimal_tec);return(1 /(int)$allowance);}public function genQueryPrice($get_price=array()){$arr_price=array();$arr_val_price=array();if(isset($get_price[1])){$arr_val_price=$get_price[1];}if(!empty($arr_val_price)){$price_min=min($arr_val_price);$price_max=max($arr_val_price);if(is_numeric($price_min)&&is_numeric($price_max)&&($price_max>=$price_min)){$code=$this->genCurrent();$tec_curs=$this->{'getCurrents'.$this->cache_fv}($code);$decimal_tec=$this->genCurrDec($code);$correct=0;if($decimal_tec==0){if($tec_curs['value']!=1){$decimal_tec=1;}if($tec_curs['value']<1){$correct=0.0499;}}$allowance_min=($this->allowancePrice($decimal_tec,1)-$correct);$allowance_max=($this->allowancePrice($decimal_tec)+$correct);$arr_price[0]=($price_min<=0.499999)?$price_min:($price_min+$allowance_min);$arr_price[1]=($price_max+$allowance_max);}}return $arr_price;}public function getCurrents_($code=null){$param='current';$key_cache=$this->genCacheParam($param,$code);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getCurrents($code);$this->cache->set($key_cache,$result);}return $result;}public function getCurrents($code=null){$rez=array();$query=$this->db->query("SELECT*FROM `".DB_PREFIX."currency`");foreach($query->rows as $result){if(!empty($result['symbol_left'])){$symbol=$result['symbol_left'];}elseif(!empty($result['symbol_right'])){$symbol=$result['symbol_right'];}else{$symbol='';}$rez[$result['code']]=array('code'=>$result['code'],'currency_id'=>$result['currency_id'],'title'=>$result['title'],'symbol'=>$symbol,'decimal_place'=>$result['decimal_place'],'value'=>$result['value']);}return(!empty($code))?$rez[$code]:$rez;}public function getOptions_($where_category){$param='optv'.'.'.$this->language_id;$key_cache=$this->genCacheParam($param,$where_category.$this->qnts_quant);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getOptions($where_category);$this->cache->set($key_cache,$result);}return $result;}public function getOptions($where_category){$poles=" pov.`option_value_id`,pov.`option_id`,od.`name` AS name_od,IF(pov.`quantity`>0,1,0)AS quantity,ovd.`name` AS name_option,ov.`image` ";$where=null;$where.=" WHERE ".$where_category." ".$this->qnts_quant;$where.=" AND od.`language_id`=".$this->language_id." ";$where.=" AND ovd.`language_id`=".$this->language_id." ";$where.=" AND pov.`quantity`>0 ";$query_str="SELECT ".$poles." FROM `".DB_PREFIX."product_option_value` pov ";$query_str.=" JOIN `".DB_PREFIX."product` p ON(pov.`product_id`=p.`product_id`)";if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{$query_str.=($this->manufacturer_id)?null:" JOIN `".DB_PREFIX."product_to_category` p2c ON(p2c.`product_id`=p.`product_id`)";}$query_str.=" LEFT JOIN `".DB_PREFIX."option` o ON(pov.`option_id`=o.`option_id`)LEFT JOIN `".DB_PREFIX."option_value_description` ovd ON(pov.`option_value_id`=ovd.`option_value_id`)LEFT JOIN `".DB_PREFIX."option_value` ov ON(ovd.`option_value_id`=ov.`option_value_id`)LEFT JOIN `".DB_PREFIX."option_description` od ON(ovd.`option_id`=od.`option_id`)";$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=" GROUP BY ovd.`name`,ovd.`option_value_id` ";$query_str.=" ORDER BY o.`sort_order`,ov.`sort_order`,ovd.`name` ASC ";$query=$this->db->query($query_str);return $query->rows;}public function countOptvProd_($where_category,$flag_count=false){$param='optv_count'.$flag_count;$key_cache=$this->genCacheParam($param,$where_category.$this->akci_tov);$result=$this->cache->get($key_cache);if(!$result){$result=$this->countOptvProd($where_category,$flag_count);$this->cache->set($key_cache,$result);}return $result;}public function countOptvProd($where_category,$flag_count=false){$pole_txt='option_value_id';$poles=" pov.`product_id`,pov.`".$pole_txt."` ";$poles.=($flag_count)?",COUNT(pov.`".$pole_txt."`)AS total ":null;$where=null;$where.=" WHERE ".$where_category." ";$where.=" AND pov.`quantity`>0 ";$query_str="SELECT ".$poles." FROM `".DB_PREFIX."product_option_value` pov ";$query_str.=" JOIN `".DB_PREFIX."product` p ON(pov.`product_id`=p.`product_id`)";if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{if($this->special&&$flag_count){$query_str.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`".$this->and_group_id.")";$where.=$this->paramPsp();}$query_str.=($this->manufacturer_id)?null:" JOIN `".DB_PREFIX."product_to_category` p2c ON(p2c.`product_id`=p.`product_id`)";}$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=($flag_count)?" GROUP BY pov.`".$pole_txt."` ":null;$query=$this->db->query($query_str);$result=array();if($flag_count){foreach($query->rows as $val){$result[$val[$pole_txt]]=$val['total'];}}else{foreach($query->rows as $val){$result[$val['product_id']][$val[$pole_txt]]=1;}}return $result;}public function sqlAttrSlider($attribute_id,$arr_val=array(),$sl=0,$and='AND'){$query_str=null;if(!empty($arr_val)){$attr_min=min($arr_val);$attr_max=max($arr_val);if(is_numeric($attr_min)&&is_numeric($attr_max)&&($attr_max>=$attr_min)){$pole='text_int';if($attr_min===$attr_max){$where_dop="=".$attr_min." ";}else{$where_dop=" BETWEEN ".$attr_min." AND ".$attr_max." ";}$where_text=" afv.`attribute_id`=".$attribute_id." AND afv.`".$pole."` ".$where_dop;if($sl!==0){$where_text=" afv.`product_id` IN(SELECT afv.`product_id` FROM `".DB_PREFIX."attribute_filter_vier` afv WHERE ".$where_text.")";}$query_str=" ".$and." ".$where_text." ";}}return $query_str;}public function getAttributes_($where_category){$param='attrb'.'.'.$this->language_id;$key_cache=$this->genCacheParam($param,$where_category.$this->qnts_quant);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getAttributes($where_category);$this->cache->set($key_cache,$result);}return $result;}public function getAttributes($where_category){$poles=" agd.`attribute_group_id`,agd.`name` AS name_group,afv.`attribute_id`,ad.`name`,afvl.`text` ";$poles.=",afv.`attr_text`,afv.`text_id` ";$where=null;$where.=" WHERE ".$where_category." ".$this->qnts_quant;$where.=" AND afvl.`language_id`=".$this->language_id." ";$where.=" AND ad.`language_id`=".$this->language_id." ";$where.=" AND agd.`language_id`=".$this->language_id." ";$query_str="SELECT ".$poles." FROM `".DB_PREFIX."attribute_filter_vier` afv ";$query_str.=" JOIN `".DB_PREFIX."product` p ON(afv.`product_id`=p.`product_id`)";$query_str.=" JOIN `".DB_PREFIX."attribute_filter_vier_lang` afvl ON(afv.`attr_text`=afvl.`attr_text`)";if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{$query_str.=($this->manufacturer_id)?null:" JOIN `".DB_PREFIX."product_to_category` p2c ON(p2c.`product_id`=p.`product_id`)";}$query_str.=" LEFT JOIN `".DB_PREFIX."attribute` a ON(afv.`attribute_id`=a.`attribute_id`)LEFT JOIN `".DB_PREFIX."attribute_description` ad ON(a.`attribute_id`=ad.`attribute_id`)LEFT JOIN `".DB_PREFIX."attribute_group_description` agd ON(a.`attribute_group_id`=agd.`attribute_group_id`)LEFT JOIN `".DB_PREFIX."attribute_group` ag ON(agd.`attribute_group_id`=ag.`attribute_group_id`)";$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=" GROUP BY afv.`attribute_id`,afv.`attr_text` ";$query_str.=" ORDER BY ag.`sort_order`,a.`sort_order`,ad.`name`,(afvl.`text`+0),afvl.`text`";$query=$this->db->query($query_str);return $query->rows;}public function countAttrbProd_($where_category,$flag_count=false){$param='attrb_count'.$flag_count;$key_cache=$this->genCacheParam($param,$where_category.$this->akci_tov);$result=$this->cache->get($key_cache);if(!$result){$result=$this->countAttrbProd($where_category,$flag_count);$this->cache->set($key_cache,$result);}return $result;}public function countAttrbProd($where_category,$flag_count=false){$pole_txt='attr_text';$poles=" afv.`product_id`,afv.`".$pole_txt."` ";$poles.=($flag_count)?",COUNT(afv.`".$pole_txt."`)AS total ":null;$where=null;$where.=" WHERE ".$where_category;$query_str_temp=null;if($this->prs_spec){$query_str_temp.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{if($this->special&&$flag_count){$query_str_temp.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`".$this->and_group_id.")";$where.=$this->paramPsp();}$query_str_temp.=($this->manufacturer_id)?null:" LEFT JOIN `".DB_PREFIX."product_to_category` p2c ON(p.`product_id`=p2c.`product_id`)";}$query_str="SELECT ".$poles." FROM `".DB_PREFIX."attribute_filter_vier` afv ";$query_str.=" LEFT JOIN `".DB_PREFIX."product` p ON(p.`product_id`=afv.`product_id`)";$query_str.=$query_str_temp;$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=($flag_count)?" GROUP BY afv.`".$pole_txt."` ":null;$query=$this->db->query($query_str);$result=array();if($flag_count){foreach($query->rows as $val){$result[$val[$pole_txt]]=$val['total'];}}else{foreach($query->rows as $val){$result[$val['product_id']][$val[$pole_txt]]=1;}}return $result;}private function isAttributesGroups($in_attr_id=null){$query_str="SELECT `attribute_group_id`,`attribute_id` FROM `".DB_PREFIX."attribute` ";$query_str.=(!empty($in_attr_id))?" WHERE `attribute_id` IN(".$in_attr_id.")":null;$query=$this->db->query($query_str);$result=array();foreach($query->rows as $id){$result[(int)$id['attribute_id']]=(int)$id['attribute_group_id'];}return $result;}private function isAttributesGroups_($in_attr_id=null){$param='groups_attrs';$key_cache=$this->genCacheParam($param,$in_attr_id);$result=$this->cache->get($key_cache);if(!$result){$result=$this->isAttributesGroups($in_attr_id);$this->cache->set($key_cache,$result);}return $result;}public function processAttrGroup($get_action_text){$result=array('key_id_first'=>false,'flag_first_count_group'=>false);$keys_param=array_keys($get_action_text);$first_attr_id=(int)$keys_param[0];$result['key_id_first']=$first_attr_id;$result['count_keys_param']=count($keys_param);$attr_group=$this->{'isAttributesGroups'.$this->cache_fv}();$result['attr_group']=$attr_group;$result['group_id_inout']=(isset($attr_group[$first_attr_id]))?(int)$attr_group[$first_attr_id]:false;$arr_group=array();foreach($keys_param as $att_id){if(isset($attr_group[$att_id])){$arr_group[$attr_group[$att_id]]=$attr_group[$att_id];}}if(count($arr_group)===1){$result['flag_first_count_group']=true;}$result['groups']=$arr_group;return $result;}public function getManufacturers_($where_category,$flag_tec_count){$param='manufs.'.$this->store_id.'.'.$flag_tec_count;$key_cache=$this->genCacheParam($param,$where_category.$this->qnts_quant.$this->akci_tov);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getManufacturers($where_category,$flag_tec_count);$this->cache->set($key_cache,$result);}return $result;}public function getManufacturers($where_category,$flag_tec_count){$poles=" m.`manufacturer_id`,p.`product_id`,m.`name`,m.`image` ";$poles.=($flag_tec_count)?",COUNT(p.`manufacturer_id`)AS total ":null;$where=null;$where.=" WHERE ".$where_category." ".$this->qnts_quant;$query_str="SELECT ".$poles." FROM `".DB_PREFIX."manufacturer` m ";if($this->mult_store){$query_str.=" RIGHT JOIN `".DB_PREFIX."manufacturer_to_store` m2s ON(m.`manufacturer_id`=m2s.`manufacturer_id`)";$where.=" AND m2s.`store_id`=".$this->store_id." ";}$query_str.=" LEFT JOIN `".DB_PREFIX."product` p ON(m.`manufacturer_id`=p.`manufacturer_id`)";if($this->akci_tov&&!$this->prs_spec){$query_str.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`)";$where.=$this->paramPsp();}if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{$query_str.=" LEFT JOIN `".DB_PREFIX."product_to_category` p2c ON(p.`product_id`=p2c.`product_id`)";}$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=" GROUP BY m.`manufacturer_id` ";$query_str.=" ORDER BY m.`sort_order`,m.`name` ASC ";$query=$this->db->query($query_str);return $query->rows;}public function countManufsProd_($where_category){$param='manufs_count1';$key_cache=$this->genCacheParam($param,$where_category.$this->akci_tov);$result=$this->cache->get($key_cache);if(!$result){$result=$this->countManufsProd($where_category);$this->cache->set($key_cache,$result);}return $result;}public function countManufsProd($where_category){$pole_txt='manufacturer_id';$poles="p.`".$pole_txt."`";$poles.=",COUNT(p.`".$pole_txt."`)AS total ";$where=null;$where.=" WHERE ".$where_category;$query_str="SELECT ".$poles." FROM `".DB_PREFIX."product` p ";if($this->prs_spec){$query_str.=$this->sql_prs_spec;$where.=" AND ".$this->polePriceSpecial()." ";}else{if($this->special){$query_str.=" ".$this->join_spec." JOIN `".DB_PREFIX."product_special` AS ps ON(p.`product_id`=ps.`product_id`".$this->and_group_id.")";$where.=$this->paramPsp();}$query_str.=" LEFT JOIN `".DB_PREFIX."product_to_category` p2c ON(p.`product_id`=p2c.`product_id`)";}$product_series=$this->productSeries();$query_str.=$product_series['sql'];$where.=$product_series['where'];$query_str.=" ".$where." ";$query_str.=" GROUP BY p.`".$pole_txt."` ";$query=$this->db->query($query_str);$result=array();foreach($query->rows as $val){$result[$val[$pole_txt]]=$val['total'];}return $result;}public function groupUser(){$customer_group_id=$this->config->get('config_customer_group_id');return(int)$customer_group_id;}public function genCacheProduct($arr_sql=array(),$language_id,$param='product'){$key_cache=$this->cach_prev.'.'.$param.'.'.$language_id.'.'.md5(http_build_query($arr_sql));return $key_cache;}public function genCacheParam($param=null,$str=null){return $this->cach_prev.'.'.$param.'.'.md5($str);}public function genCacheParam1($param=null){return $this->cach_prev.'.'.$param;}public function genSetting(){$param='filter_vier_setting';if($this->cache_fv){$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->config->get($param);$this->cache->set($key_cache,$result);}}else{$result=$this->config->get($param);}return $result;}public function genCurrent(){return $this->session->data['currency'];}public function getConfLang(){return(int)$this->config->get('config_language_id');}public function defaultCodeLang(){return $this->config->get('config_language');}public function getConfStore(){return(int)$this->config->get('config_store_id');}public function getConfTax(){return $this->config->get('config_tax');}public function getFlatTaxClassId(){return $this->config->get('flat_tax_class_id');}public function genSettingCache(){$result=false;if($this->config->get('filter_vier_cache')){$result=true;}return $result;}private function getConfCpu(){return $this->config->get('filter_vier_cpu');}public function genCurrDec($code){return(int)$this->currency->getDecimalPlace($code);}public function validGet($vid='arr'){$result=array();if(isset($this->request->get)){foreach($this->request->get as $key=>$val){$arr_rez=array();if(in_array($key,$this->actions_get)){if(is_array($val)){$arr_rez=$this->model_module_filter_vier->getValidFilter($val);if(isset($arr_rez[$vid])){$result[$key]=$arr_rez[$vid];}}}}}return $result;}public function getValidFilter($arr){$result=array('arr'=>array(),'str'=>array());if(!is_array($arr))return $result;foreach($arr as $k_id=>$val){if(is_numeric($k_id)&&(is_string($val)|| is_numeric($val))){$arr1=explode($this->delit_param,(string)$val);$arr_temp=array();if(!empty($arr1)){foreach($arr1 as $v){if(is_numeric($v)){$arr_temp[]=$v;}else{return array();}}if(!empty($arr_temp)){$result['arr'][$k_id]=$arr_temp;$result['str'][$k_id]=implode($this->delit_param,$arr_temp);}}}else{return array();}}return $result;}public function validGetNum($get_key){$result=false;if(!isset($this->request->get['path'])&&isset($this->request->get[$get_key])&&is_numeric($num=$this->request->get[$get_key])){$result=(int)$num;}return $result;}public function genUrlPlus($amp='&'){$url=null;$arr_get_action=$this->validGet('str');if(!empty($arr_get_action)){foreach($arr_get_action as $key=>$val){foreach($val as $k=>$v){$url.=$amp.$key.'['.$k.']='.$v;}}}return $url;}public function baseUrlSeo_(){$result=array();$query=$this->db->query("SELECT `main_key`,`main_id`,`key_id`,`seo_url` FROM `".DB_PREFIX."url_filter_vier`");foreach($query->rows as $colum){$result[$colum['main_key']][$colum['main_id']][$colum['key_id']]=$colum['seo_url'];}return $result;}public function baseUrlSeo(){$param='url_base_seo';if($this->cache_fv){$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->baseUrlSeo_();$this->cache->set($key_cache,$result);}}else{$result=$this->baseUrlSeo_();}return $result;}private function baseUrlKey_(){$result=array();$query=$this->db->query("SELECT `main_key`,`key_param`,`key_param1`,`main_id`,`key_id`,`seo_url` FROM `".DB_PREFIX."url_filter_vier` ORDER BY `main_key`,`main_id`,`key_id` ASC");foreach($query->rows as $colum){$result['key_param'][$colum['key_param']]=$colum['seo_url'];$result['key_param1'][$colum['key_param1']]=$colum['key_id'];}return $result;}private function baseUrlKey(){$param='url_base_key';if($this->cache_fv){$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->baseUrlKey_();$this->cache->set($key_cache,$result);}}else{$result=$this->baseUrlKey_();}return $result;}private function getUri(){$req_uri=$this->request->server['REQUEST_URI'];if(strpos($req_uri,'?')!==false){$str=strstr($req_uri,'?',true);}else{$str=$req_uri;}return $str;}public function linkPages(){$result=array();$arr_discr_hand=$this->getDiscriptHang();if($arr_discr_hand){foreach($this->poles_landing as $pole){$result[$pole]=isset($arr_discr_hand[$pole][$this->language_id])?$arr_discr_hand[$pole][$this->language_id]:'';}}return $result;}public function filterVierCpu_(){$get_base=$this->set_cpu;$result=array('meta_tags'=>false,'link_pages'=>false,'h_head'=>false,'no_price'=>false,'canonical'=>false,'redir_url'=>false,'h_descript'=>false,'canonic_view'=>array(),'no_gua_qv_now'=>false,'h_descript_base'=>false,'h_descript_base_plus'=>false,'noindex_rel'=>false,'noindex_page'=>false,'noindex_all'=>false,'noindex'=>null);if(!empty($get_base)&&is_array($get_base)){foreach($get_base as $k=>$v){if(($k=='separators')||($k=='lang_translit'))continue;$result[$k]=$v;}}return $result;}public function filterVierCpu(){$param='filter_vier_cpu';if($this->cache_fv){$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->filterVierCpu_();$this->cache->set($key_cache,$result);}}else{$result=$this->filterVierCpu_();}return $result;}public function getUrlSeoStr($arr_seo_url=array(),$pz,$key_id,$val_i,$separ){$result=array('seo_url'=>null,'arr_val_i'=>array());$temp_id=array();$arr_val_i=array();$main_param=null;$main_id='0';$flag_url=true;if(isset($arr_seo_url[$pz][$key_id][$main_id])){$main_param=$arr_seo_url[$pz][$key_id][$main_id];if(empty($main_param)){$flag_url=false;$arr_val_i[]=$main_id;}}else{$flag_url=false;foreach($val_i as $id){$arr_val_i[]=$id;}}$flag_=($main_param&&(($pz=='prs')||(($pz=='attrb')&&isset($this->sliders_attrb[$key_id]))))?true:false;$i=0;foreach($val_i as $key=>$id){if($flag_)continue;if($flag_url&&($id!=$main_id)){if(isset($arr_seo_url[$pz][$key_id][$id])){$temp_id[$i++]=$arr_seo_url[$pz][$key_id][$id];}else{$arr_val_i[]=$id;}}}if($flag_){$temp_pr=array();foreach($val_i as $v_pr){$temp_pr[]=str_replace('.',$this->cent,$v_pr);}$url_temp=$main_param.$separ[0].implode($separ[1],$temp_pr);}elseif($temp_id){$url_temp=$main_param.$separ[0].implode($separ[1],$temp_id);}else{if(!$arr_val_i){$url_temp=$main_param;}}if(!empty($url_temp)){$result['seo_url']=$url_temp;}if(!empty($arr_val_i)){$result['arr_val_i']=$arr_val_i;}return $result;}public function getUrlSeoFV($pz,$arr_val){$result=false;if($this->seoUrl()){$url=null;$actions_get=$this->actionsGet();if(is_string($pz)&&in_array($pz,$actions_get)){$arr_valid=$this->getValidFilter($arr_val);if(isset($arr_valid['arr'])&&!empty($arr_valid['arr'])){$arr_seo_url=$this->baseUrlSeo();$separ=$this->separatorsFV();$url_temp=array();$main_id=0;foreach($arr_valid['arr'] as $key_id=>$val_i){$res=$this->getUrlSeoStr($arr_seo_url,$pz,$key_id,$val_i,$separ);$url_temp[]=$res['seo_url'];}if(!empty($url_temp)){$url=implode($separ[2],$url_temp);$result=trim($url,'/');}}}if($result){$result.=$this->post_slash;}}return $result;}public function delPostfixSlashe($url,$postfix=null,$del_slash=true){$postfix=(is_null($postfix))?$this->genPostFix():$postfix;if($postfix&&($postfix!='/')){$url=str_ireplace($postfix,'',$url);}return($del_slash)?rtrim($url,'/'):$url;}public function parseUrlSeoFV($part){$result=false;if(!$this->seoUrl())return $result;$delit_param=$this->delit_param;$separ=$this->separatorsFV();$sep_0=$separ[0];$sep_1=$separ[1];$sep_2=$separ[2];if(is_string($part)&&($key_url=$this->baseUrlKey())){$bloks=explode($sep_2,$part);foreach($bloks as $bloki){$blok=explode($sep_0,$bloki);$url_main=$blok[0];$key_id=array();$flag=false;if($arr_main=array_search($url_main,$key_url['key_param'])){if($arr_main!==false){$main_key_id=explode('_',$arr_main);$main_key=$main_key_id[0];$main_id=$main_key_id[1];$key_id=$main_key_id[2];$flag=true;}}if($flag){$key_id_arr=array();if(count($blok)===1){if($main_key=='manufs')return $result;$key_id_arr[]=$key_id;if(isset($this->request->get[$main_key][$main_id])){$key_id_arr[]=$this->request->get[$main_key][$main_id];}}else{$params=explode($sep_1,$blok[1]);foreach($params as $param){$flag_param=false;if(($main_key=='prs')||(($main_key=='attrb')&&isset($this->sliders_attrb[$main_id]))){$key_id=str_replace($this->cent,'.',$param);$key_id_arr[]=$key_id;$flag_param=true;}elseif(isset($key_url['key_param1'][$main_key.'='.$main_id.'_'.$param])){$key_id=$key_url['key_param1'][$main_key.'='.$main_id.'_'.$param];$key_id_arr[]=$key_id;$flag_param=true;}if($flag_param){$key_id_arr[]=$key_id;if(isset($this->request->get[$main_key][$main_id])){$key_id_arr[]=$this->request->get[$main_key][$main_id];}}}}if(!empty($key_id_arr)){$key_id_arr=array_unique($key_id_arr);$str=implode($delit_param,$key_id_arr);$this->request->get[$main_key][$main_id]=$str;$arr_get=array($main_key=>array($main_id=>$str));$result=$arr_get;}}}}return $result;}public function getDiscriptFV_($language_id,$pole){$param='filter_vier_description.'.$pole.'.'.$language_id;$key_cache=$this->genCacheParam1($param);$result=$this->cache->get($key_cache);if(!$result){$result=$this->getDiscriptFV($language_id,$pole);$this->cache->set($key_cache,$result);}return $result;}public function getDiscriptFV($language_id,$pole){$result=array();$where=($language_id)?" WHERE `language_id`=".(int)$language_id:null;$query=$this->db->query("SELECT `".$pole."` FROM `".DB_PREFIX."filter_vier_description` ".$where);