Get('view'); $view_switch = Tools_Http::Get('view'); if($view_switch) $view = $view_switch; $session->Set('view',$view); $products = new Products(); $searchClass = new Products_Searches(); $PageData = Common_Page::getInstance(); $mode= isset($m_params['filter']) ? $m_params['filter'] : 'default'; if (isset($m_params)) { $catid = isset($m_params['catid']) ? $m_params['catid'] : 0; $car_make = !empty($m_params['car_make']) > 0 ? $m_params['car_make'] : 0; } else { $catid = defined ('catid') ? catid : 0; $car_make = defined ('car_make') ? car_make : 0; //Tools_Http::Get('filter_make',true) } $params = array( 'length' => $rpp, 'offset' => $page, 'order' => 'price asc' ); $fields = array(); if ($catid) { $fields['catid'][1] = $catid; $fields['catid'][2] =$catid; $fields['catid'][3] =$catid; $fields['catid'][4] =$catid; } if ($car_make) { $fields['carid'] = $car_make; } if (isset($search) && !empty($search)) { //$search = $DB->Escape($search); //echo strlen($search); $search = str_replace('!','',$search); $search = str_replace(' - ',' ',$search); $search = trim($search); $search_array=explode(' ',$search); $c=1; $pp = $page; if(!$page) $pp = 1; $per_page = 100; // SPHINX $keywords = explode(" ", $search); $keyword=''; foreach($keywords as $k) if(strlen($k)>1) $keyword.='+'.$k.'* '; $sq = ''; foreach($keywords as $str) { $sq .= $str.'* '; } $cl = new SphinxClient(); $cl->SetServer('localhost', 3313); $opts = array ( "before_match" => "", "after_match" => "", "chunk_separator" => " ... ", "limit" => 70, "around" => 3, ); $cl->SetSortMode ( SPH_SORT_ATTR_ASC, 'price' ); $cl->SetMatchMode(SPH_MATCH_EXTENDED2); $cl->SetRankingMode( SPH_RANK_PROXIMITY_BM25 ); $cl-> SetLimits(($pp-1)* $per_page,$per_page,$per_page+(($pp-1)* $per_page)); $result = $cl->Query($sq,'main_products_lv'); // print_r($result['matches']); if ($result && isset($result['matches']) && is_array($result['matches'])) { $ids = array_keys($result['matches']); $all_ids = implode(',',$ids); } $fields['id'] = $ids; /* foreach($search_array as $string) { $fields['search'][] =trim($string); // if(count($search_array)>1 && $c!=count($search_array)) $fields['title'] .= ' AND LIKE'; // $c++; } */ } else $search=''; if ($mode == 'newest') { $fields['new'] = 1; } if ($mode == 'sale') { $fields['sale'] = 1; } //$fields['active']=1; $goods = $products -> getList ($fields, $params); if (isset($search) && !empty($search)) { $searchClass->insertSearch($search,$goods['total']); $phrase_id = $searchClass->getIdByPhrase($search); if($phrase_id) $phraseData = $searchClass->getPhraseDetails($phrase_id); else $phraseData = array(); } $top = array(); //$top['popular'] = $products ->getProductsTop(5,21,$catid); //$top['sales'] = $products ->getCategorySales(5,21,$catid); $page_client_card = $PageData->getPageData(119); //print_r($goods); $goods_items = $goods['data']; $total_items = $goods['total']; $category_title = ''; if(isset($cat_item['id'])) { $category_title =$L->StrT('goods_categories','title', $cat_item['id'], $cat_item['title']); $Template->description = $category_title; } foreach($goods_items as $good) { $title = $good['good_name']; $k = explode(' ',$title); foreach($k as $kk) { $keywords_all[$kk]=1; } } $m=0; $keywords = array(); foreach($keywords_all as $key => $val) { $m++; if($m>5) continue; if(strlen($key)>2) $keywords[]=$key; } $Template->keywords = implode(' ,',$keywords); $m_return .= '
'; if(!$search) { $m_return .= '

'.$category_title.'

'; $m_return .= '
'; $m_return .= '
'; $m_return .= '
'; } else $m_return .= '

'.$search.'

'; $phrases=array(); /* if(!empty($search_array)) { foreach($search_array as $string) { $query='SELECT phrase FROM searches WHERE `phrase` LIKE "%'.$string.'%" AND `phrase` NOT LIKE "'.implode(' ',$search_array).'" AND found >0 AND searches_count>1 order by RAND() LIMIT 5 '; //echo $query; $row_query = $DB->Exec($query); while(list($phrase) = $DB->FetchRow($row_query)) { if(!in_array($phrase,$phrases)) $phrases[] = $phrase; if(count($phrases)>10) continue; } } } */ if(count($phrases)>0 && 1==2) { $m_return .= '
'.$L->Str('search_also').': '; foreach($phrases as $phrase) { $link=str_replace(' ','+',$phrase); $m_return .= ''.$phrase.''; } $m_return .='
'; } $m_return .='
'; if($view=='blocks') { if(isset($phraseData['products']) && !empty($phraseData['products']) && !$page) $m_return .= Common_Template::goodsBlock($phraseData['products']); else if (!empty($goods_items) ) $m_return .= Common_Template::goodsBlock($goods_items); } if($view=='list' || !$view) { if(isset($phraseData['products']) && !empty($phraseData['products']) && !$page) foreach($phraseData['products'] as $item) $m_return .= Common_Template::goodsBoxDefault($item,false,$category_title,$top,$page_client_card); if (!empty($goods_items) ) { foreach ($goods_items as $item) { $item['search_title'] = $search; $m_return .= Common_Template::goodsBoxDefault($item,false,$category_title,$top,$page_client_card); } } } if( (isset($phraseData['products']) && !empty($phraseData['products']) && !$page) && !empty($goods_items)) { $m_return .= '

'.$L->Str('No products in this category').'

'; $m_return .= '

'.$L->Str('Browse shop').'

'; } $m_return .= '
'; $m_return .= Tools_Common:: pageSelector ($total_items, $rpp, $page, '', 10); $m_return .= '
';