search.php (15343B)
1 <?php 2 class ControllerProductSearch extends Controller { 3 public function index() { 4 $this->load->language('product/search'); 5 6 $this->load->model('catalog/category'); 7 8 $this->load->model('catalog/product'); 9 10 $this->load->model('tool/image'); 11 12 if (isset($this->request->get['search'])) { 13 $search = $this->request->get['search']; 14 } else { 15 $search = ''; 16 } 17 18 if (isset($this->request->get['tag'])) { 19 $tag = $this->request->get['tag']; 20 } elseif (isset($this->request->get['search'])) { 21 $tag = $this->request->get['search']; 22 } else { 23 $tag = ''; 24 } 25 26 if (isset($this->request->get['description'])) { 27 $description = $this->request->get['description']; 28 } else { 29 $description = ''; 30 } 31 32 if (isset($this->request->get['category_id'])) { 33 $category_id = $this->request->get['category_id']; 34 } else { 35 $category_id = 0; 36 } 37 38 if (isset($this->request->get['sub_category'])) { 39 $sub_category = $this->request->get['sub_category']; 40 } else { 41 $sub_category = ''; 42 } 43 44 if (isset($this->request->get['sort'])) { 45 $sort = $this->request->get['sort']; 46 } else { 47 $sort = 'p.sort_order'; 48 } 49 50 if (isset($this->request->get['order'])) { 51 $order = $this->request->get['order']; 52 } else { 53 $order = 'ASC'; 54 } 55 56 if (isset($this->request->get['page'])) { 57 $page = $this->request->get['page']; 58 } else { 59 $page = 1; 60 } 61 62 if (isset($this->request->get['limit'])) { 63 $limit = (int)$this->request->get['limit']; 64 } else { 65 $limit = $this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'); 66 } 67 68 if (isset($this->request->get['search'])) { 69 $this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->request->get['search']); 70 } elseif (isset($this->request->get['tag'])) { 71 $this->document->setTitle($this->language->get('heading_title') . ' - ' . $this->language->get('heading_tag') . $this->request->get['tag']); 72 } else { 73 $this->document->setTitle($this->language->get('heading_title')); 74 } 75 76 $data['breadcrumbs'] = array(); 77 78 $data['breadcrumbs'][] = array( 79 'text' => $this->language->get('text_home'), 80 'href' => $this->url->link('common/home') 81 ); 82 83 $url = ''; 84 85 if (isset($this->request->get['search'])) { 86 $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8')); 87 } 88 89 if (isset($this->request->get['tag'])) { 90 $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8')); 91 } 92 93 if (isset($this->request->get['description'])) { 94 $url .= '&description=' . $this->request->get['description']; 95 } 96 97 if (isset($this->request->get['category_id'])) { 98 $url .= '&category_id=' . $this->request->get['category_id']; 99 } 100 101 if (isset($this->request->get['sub_category'])) { 102 $url .= '&sub_category=' . $this->request->get['sub_category']; 103 } 104 105 if (isset($this->request->get['sort'])) { 106 $url .= '&sort=' . $this->request->get['sort']; 107 } 108 109 if (isset($this->request->get['order'])) { 110 $url .= '&order=' . $this->request->get['order']; 111 } 112 113 if (isset($this->request->get['page'])) { 114 $url .= '&page=' . $this->request->get['page']; 115 } 116 117 if (isset($this->request->get['limit'])) { 118 $url .= '&limit=' . $this->request->get['limit']; 119 } 120 121 $data['breadcrumbs'][] = array( 122 'text' => $this->language->get('heading_title'), 123 'href' => $this->url->link('product/search', $url) 124 ); 125 126 if (isset($this->request->get['search'])) { 127 $data['heading_title'] = $this->language->get('heading_title') . ' - ' . $this->request->get['search']; 128 } else { 129 $data['heading_title'] = $this->language->get('heading_title'); 130 } 131 132 $data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0)); 133 134 $data['compare'] = $this->url->link('product/compare'); 135 136 $this->load->model('catalog/category'); 137 138 // 3 Level Category Search 139 $data['categories'] = array(); 140 141 $categories_1 = $this->model_catalog_category->getCategories(0); 142 143 foreach ($categories_1 as $category_1) { 144 $level_2_data = array(); 145 146 $categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']); 147 148 foreach ($categories_2 as $category_2) { 149 $level_3_data = array(); 150 151 $categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']); 152 153 foreach ($categories_3 as $category_3) { 154 $level_3_data[] = array( 155 'category_id' => $category_3['category_id'], 156 'name' => $category_3['name'], 157 ); 158 } 159 160 $level_2_data[] = array( 161 'category_id' => $category_2['category_id'], 162 'name' => $category_2['name'], 163 'children' => $level_3_data 164 ); 165 } 166 167 $data['categories'][] = array( 168 'category_id' => $category_1['category_id'], 169 'name' => $category_1['name'], 170 'children' => $level_2_data 171 ); 172 } 173 174 $data['products'] = array(); 175 176 if (isset($this->request->get['search']) || isset($this->request->get['tag'])) { 177 $filter_data = array( 178 'filter_name' => $search, 179 'filter_tag' => $tag, 180 'filter_description' => $description, 181 'filter_category_id' => $category_id, 182 'filter_sub_category' => $sub_category, 183 'sort' => $sort, 184 'order' => $order, 185 'start' => ($page - 1) * $limit, 186 'limit' => $limit 187 ); 188 189 $product_total = $this->model_catalog_product->getTotalProducts($filter_data); 190 191 $results = $this->model_catalog_product->getProducts($filter_data); 192 193 foreach ($results as $result) { 194 if ($result['image']) { 195 $image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height')); 196 } else { 197 $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height')); 198 } 199 200 if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { 201 $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 202 } else { 203 $price = false; 204 } 205 206 if ((float)$result['special']) { 207 $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 208 } else { 209 $special = false; 210 } 211 212 if ($this->config->get('config_tax')) { 213 $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']); 214 } else { 215 $tax = false; 216 } 217 218 if ($this->config->get('config_review_status')) { 219 $rating = (int)$result['rating']; 220 } else { 221 $rating = false; 222 } 223 224 $data['products'][] = array( 225 'product_id' => $result['product_id'], 226 'thumb' => $image, 227 'name' => $result['name'], 228 'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..', 229 'price' => $price, 230 'special' => $special, 231 'tax' => $tax, 232 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1, 233 'rating' => $result['rating'], 234 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url) 235 ); 236 } 237 238 $url = ''; 239 240 if (isset($this->request->get['search'])) { 241 $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8')); 242 } 243 244 if (isset($this->request->get['tag'])) { 245 $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8')); 246 } 247 248 if (isset($this->request->get['description'])) { 249 $url .= '&description=' . $this->request->get['description']; 250 } 251 252 if (isset($this->request->get['category_id'])) { 253 $url .= '&category_id=' . $this->request->get['category_id']; 254 } 255 256 if (isset($this->request->get['sub_category'])) { 257 $url .= '&sub_category=' . $this->request->get['sub_category']; 258 } 259 260 if (isset($this->request->get['limit'])) { 261 $url .= '&limit=' . $this->request->get['limit']; 262 } 263 264 $data['sorts'] = array(); 265 266 $data['sorts'][] = array( 267 'text' => $this->language->get('text_default'), 268 'value' => 'p.sort_order-ASC', 269 'href' => $this->url->link('product/search', 'sort=p.sort_order&order=ASC' . $url) 270 ); 271 272 $data['sorts'][] = array( 273 'text' => $this->language->get('text_name_asc'), 274 'value' => 'pd.name-ASC', 275 'href' => $this->url->link('product/search', 'sort=pd.name&order=ASC' . $url) 276 ); 277 278 $data['sorts'][] = array( 279 'text' => $this->language->get('text_name_desc'), 280 'value' => 'pd.name-DESC', 281 'href' => $this->url->link('product/search', 'sort=pd.name&order=DESC' . $url) 282 ); 283 284 $data['sorts'][] = array( 285 'text' => $this->language->get('text_price_asc'), 286 'value' => 'p.price-ASC', 287 'href' => $this->url->link('product/search', 'sort=p.price&order=ASC' . $url) 288 ); 289 290 $data['sorts'][] = array( 291 'text' => $this->language->get('text_price_desc'), 292 'value' => 'p.price-DESC', 293 'href' => $this->url->link('product/search', 'sort=p.price&order=DESC' . $url) 294 ); 295 296 if ($this->config->get('config_review_status')) { 297 $data['sorts'][] = array( 298 'text' => $this->language->get('text_rating_desc'), 299 'value' => 'rating-DESC', 300 'href' => $this->url->link('product/search', 'sort=rating&order=DESC' . $url) 301 ); 302 303 $data['sorts'][] = array( 304 'text' => $this->language->get('text_rating_asc'), 305 'value' => 'rating-ASC', 306 'href' => $this->url->link('product/search', 'sort=rating&order=ASC' . $url) 307 ); 308 } 309 310 $data['sorts'][] = array( 311 'text' => $this->language->get('text_model_asc'), 312 'value' => 'p.model-ASC', 313 'href' => $this->url->link('product/search', 'sort=p.model&order=ASC' . $url) 314 ); 315 316 $data['sorts'][] = array( 317 'text' => $this->language->get('text_model_desc'), 318 'value' => 'p.model-DESC', 319 'href' => $this->url->link('product/search', 'sort=p.model&order=DESC' . $url) 320 ); 321 322 $url = ''; 323 324 if (isset($this->request->get['search'])) { 325 $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8')); 326 } 327 328 if (isset($this->request->get['tag'])) { 329 $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8')); 330 } 331 332 if (isset($this->request->get['description'])) { 333 $url .= '&description=' . $this->request->get['description']; 334 } 335 336 if (isset($this->request->get['category_id'])) { 337 $url .= '&category_id=' . $this->request->get['category_id']; 338 } 339 340 if (isset($this->request->get['sub_category'])) { 341 $url .= '&sub_category=' . $this->request->get['sub_category']; 342 } 343 344 if (isset($this->request->get['sort'])) { 345 $url .= '&sort=' . $this->request->get['sort']; 346 } 347 348 if (isset($this->request->get['order'])) { 349 $url .= '&order=' . $this->request->get['order']; 350 } 351 352 $data['limits'] = array(); 353 354 $limits = array_unique(array($this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100)); 355 356 sort($limits); 357 358 foreach($limits as $value) { 359 $data['limits'][] = array( 360 'text' => $value, 361 'value' => $value, 362 'href' => $this->url->link('product/search', $url . '&limit=' . $value) 363 ); 364 } 365 366 $url = ''; 367 368 if (isset($this->request->get['search'])) { 369 $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8')); 370 } 371 372 if (isset($this->request->get['tag'])) { 373 $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8')); 374 } 375 376 if (isset($this->request->get['description'])) { 377 $url .= '&description=' . $this->request->get['description']; 378 } 379 380 if (isset($this->request->get['category_id'])) { 381 $url .= '&category_id=' . $this->request->get['category_id']; 382 } 383 384 if (isset($this->request->get['sub_category'])) { 385 $url .= '&sub_category=' . $this->request->get['sub_category']; 386 } 387 388 if (isset($this->request->get['sort'])) { 389 $url .= '&sort=' . $this->request->get['sort']; 390 } 391 392 if (isset($this->request->get['order'])) { 393 $url .= '&order=' . $this->request->get['order']; 394 } 395 396 if (isset($this->request->get['limit'])) { 397 $url .= '&limit=' . $this->request->get['limit']; 398 } 399 400 $pagination = new Pagination(); 401 $pagination->total = $product_total; 402 $pagination->page = $page; 403 $pagination->limit = $limit; 404 $pagination->url = $this->url->link('product/search', $url . '&page={page}'); 405 406 $data['pagination'] = $pagination->render(); 407 408 $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit)); 409 410 if (isset($this->request->get['search']) && $this->config->get('config_customer_search')) { 411 $this->load->model('account/search'); 412 413 if ($this->customer->isLogged()) { 414 $customer_id = $this->customer->getId(); 415 } else { 416 $customer_id = 0; 417 } 418 419 if (isset($this->request->server['REMOTE_ADDR'])) { 420 $ip = $this->request->server['REMOTE_ADDR']; 421 } else { 422 $ip = ''; 423 } 424 425 $search_data = array( 426 'keyword' => $search, 427 'category_id' => $category_id, 428 'sub_category' => $sub_category, 429 'description' => $description, 430 'products' => $product_total, 431 'customer_id' => $customer_id, 432 'ip' => $ip 433 ); 434 435 $this->model_account_search->addSearch($search_data); 436 } 437 } 438 439 $data['search'] = $search; 440 $data['description'] = $description; 441 $data['category_id'] = $category_id; 442 $data['sub_category'] = $sub_category; 443 444 $data['sort'] = $sort; 445 $data['order'] = $order; 446 $data['limit'] = $limit; 447 448 $data['column_left'] = $this->load->controller('common/column_left'); 449 $data['column_right'] = $this->load->controller('common/column_right'); 450 $data['content_top'] = $this->load->controller('common/content_top'); 451 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 452 $data['footer'] = $this->load->controller('common/footer'); 453 $data['header'] = $this->load->controller('common/header'); 454 455 $this->response->setOutput($this->load->view('product/search', $data)); 456 } 457 }