manufacturer.php (14795B)
1 <?php 2 class ControllerProductManufacturer extends Controller { 3 public function index() { 4 $this->load->language('product/manufacturer'); 5 6 $this->load->model('catalog/manufacturer'); 7 8 $this->load->model('tool/image'); 9 10 $this->document->setTitle($this->language->get('heading_title')); 11 12 $data['breadcrumbs'] = array(); 13 14 $data['breadcrumbs'][] = array( 15 'text' => $this->language->get('text_home'), 16 'href' => $this->url->link('common/home') 17 ); 18 19 $data['breadcrumbs'][] = array( 20 'text' => $this->language->get('text_brand'), 21 'href' => $this->url->link('product/manufacturer') 22 ); 23 24 $data['categories'] = array(); 25 26 $results = $this->model_catalog_manufacturer->getManufacturers(); 27 28 foreach ($results as $result) { 29 if (is_numeric(utf8_substr($result['name'], 0, 1))) { 30 $key = '0 - 9'; 31 } else { 32 $key = utf8_substr(utf8_strtoupper($result['name']), 0, 1); 33 } 34 35 if (!isset($data['categories'][$key])) { 36 $data['categories'][$key]['name'] = $key; 37 } 38 39 $data['categories'][$key]['manufacturer'][] = array( 40 'name' => $result['name'], 41 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id']) 42 ); 43 } 44 45 $data['continue'] = $this->url->link('common/home'); 46 47 $data['column_left'] = $this->load->controller('common/column_left'); 48 $data['column_right'] = $this->load->controller('common/column_right'); 49 $data['content_top'] = $this->load->controller('common/content_top'); 50 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 51 $data['footer'] = $this->load->controller('common/footer'); 52 $data['header'] = $this->load->controller('common/header'); 53 54 $this->response->setOutput($this->load->view('product/manufacturer_list', $data)); 55 } 56 57 public function info() { 58 $this->load->language('product/manufacturer'); 59 60 $this->load->model('catalog/manufacturer'); 61 62 $this->load->model('catalog/product'); 63 64 $this->load->model('tool/image'); 65 66 if (isset($this->request->get['manufacturer_id'])) { 67 $manufacturer_id = (int)$this->request->get['manufacturer_id']; 68 } else { 69 $manufacturer_id = 0; 70 } 71 72 if (isset($this->request->get['sort'])) { 73 $sort = $this->request->get['sort']; 74 } else { 75 $sort = 'p.sort_order'; 76 } 77 78 if (isset($this->request->get['order'])) { 79 $order = $this->request->get['order']; 80 } else { 81 $order = 'ASC'; 82 } 83 84 if (isset($this->request->get['page'])) { 85 $page = $this->request->get['page']; 86 } else { 87 $page = 1; 88 } 89 90 if (isset($this->request->get['limit'])) { 91 $limit = (int)$this->request->get['limit']; 92 } else { 93 $limit = (int)$this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'); 94 } 95 96 $data['breadcrumbs'] = array(); 97 98 $data['breadcrumbs'][] = array( 99 'text' => $this->language->get('text_home'), 100 'href' => $this->url->link('common/home') 101 ); 102 103 $data['breadcrumbs'][] = array( 104 'text' => $this->language->get('text_brand'), 105 'href' => $this->url->link('product/manufacturer') 106 ); 107 108 $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id); 109 110 if ($manufacturer_info) { 111 $this->document->setTitle($manufacturer_info['name']); 112 113 $url = ''; 114 115 if (isset($this->request->get['sort'])) { 116 $url .= '&sort=' . $this->request->get['sort']; 117 } 118 119 if (isset($this->request->get['order'])) { 120 $url .= '&order=' . $this->request->get['order']; 121 } 122 123 if (isset($this->request->get['page'])) { 124 $url .= '&page=' . $this->request->get['page']; 125 } 126 127 if (isset($this->request->get['limit'])) { 128 $url .= '&limit=' . $this->request->get['limit']; 129 } 130 131 $data['breadcrumbs'][] = array( 132 'text' => $manufacturer_info['name'], 133 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url) 134 ); 135 136 $data['heading_title'] = $manufacturer_info['name']; 137 138 $data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0)); 139 140 $data['compare'] = $this->url->link('product/compare'); 141 142 $data['products'] = array(); 143 144 $filter_data = array( 145 'filter_manufacturer_id' => $manufacturer_id, 146 'sort' => $sort, 147 'order' => $order, 148 'start' => ($page - 1) * $limit, 149 'limit' => $limit 150 ); 151 152 $product_total = $this->model_catalog_product->getTotalProducts($filter_data); 153 154 $results = $this->model_catalog_product->getProducts($filter_data); 155 156 foreach ($results as $result) { 157 if ($result['image']) { 158 $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')); 159 } else { 160 $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')); 161 } 162 163 if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { 164 $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 165 } else { 166 $price = false; 167 } 168 169 if ((float)$result['special']) { 170 $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 171 } else { 172 $special = false; 173 } 174 175 if ($this->config->get('config_tax')) { 176 $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']); 177 } else { 178 $tax = false; 179 } 180 181 if ($this->config->get('config_review_status')) { 182 $rating = (int)$result['rating']; 183 } else { 184 $rating = false; 185 } 186 187 $data['products'][] = array( 188 'product_id' => $result['product_id'], 189 'thumb' => $image, 190 'name' => $result['name'], 191 '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')) . '..', 192 'price' => $price, 193 'special' => $special, 194 'tax' => $tax, 195 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1, 196 'rating' => $result['rating'], 197 'href' => $this->url->link('product/product', 'manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url) 198 ); 199 } 200 201 $url = ''; 202 203 if (isset($this->request->get['limit'])) { 204 $url .= '&limit=' . $this->request->get['limit']; 205 } 206 207 $data['sorts'] = array(); 208 209 $data['sorts'][] = array( 210 'text' => $this->language->get('text_default'), 211 'value' => 'p.sort_order-ASC', 212 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url) 213 ); 214 215 $data['sorts'][] = array( 216 'text' => $this->language->get('text_name_asc'), 217 'value' => 'pd.name-ASC', 218 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url) 219 ); 220 221 $data['sorts'][] = array( 222 'text' => $this->language->get('text_name_desc'), 223 'value' => 'pd.name-DESC', 224 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url) 225 ); 226 227 $data['sorts'][] = array( 228 'text' => $this->language->get('text_price_asc'), 229 'value' => 'p.price-ASC', 230 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url) 231 ); 232 233 $data['sorts'][] = array( 234 'text' => $this->language->get('text_price_desc'), 235 'value' => 'p.price-DESC', 236 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url) 237 ); 238 239 if ($this->config->get('config_review_status')) { 240 $data['sorts'][] = array( 241 'text' => $this->language->get('text_rating_desc'), 242 'value' => 'rating-DESC', 243 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url) 244 ); 245 246 $data['sorts'][] = array( 247 'text' => $this->language->get('text_rating_asc'), 248 'value' => 'rating-ASC', 249 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url) 250 ); 251 } 252 253 $data['sorts'][] = array( 254 'text' => $this->language->get('text_model_asc'), 255 'value' => 'p.model-ASC', 256 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url) 257 ); 258 259 $data['sorts'][] = array( 260 'text' => $this->language->get('text_model_desc'), 261 'value' => 'p.model-DESC', 262 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url) 263 ); 264 265 $url = ''; 266 267 if (isset($this->request->get['sort'])) { 268 $url .= '&sort=' . $this->request->get['sort']; 269 } 270 271 if (isset($this->request->get['order'])) { 272 $url .= '&order=' . $this->request->get['order']; 273 } 274 275 $data['limits'] = array(); 276 277 $limits = array_unique(array($this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100)); 278 279 sort($limits); 280 281 foreach($limits as $value) { 282 $data['limits'][] = array( 283 'text' => $value, 284 'value' => $value, 285 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value) 286 ); 287 } 288 289 $url = ''; 290 291 if (isset($this->request->get['sort'])) { 292 $url .= '&sort=' . $this->request->get['sort']; 293 } 294 295 if (isset($this->request->get['order'])) { 296 $url .= '&order=' . $this->request->get['order']; 297 } 298 299 if (isset($this->request->get['limit'])) { 300 $url .= '&limit=' . $this->request->get['limit']; 301 } 302 303 $pagination = new Pagination(); 304 $pagination->total = $product_total; 305 $pagination->page = $page; 306 $pagination->limit = $limit; 307 $pagination->url = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}'); 308 309 $data['pagination'] = $pagination->render(); 310 311 $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)); 312 313 // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html 314 if ($page == 1) { 315 $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'], true), 'canonical'); 316 } else { 317 $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page='. $page, true), 'canonical'); 318 } 319 320 if ($page > 1) { 321 $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page='. (($page - 2) ? '&page='. ($page - 1) : ''), true), 'prev'); 322 } 323 324 if ($limit && ceil($product_total / $limit) > $page) { 325 $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page='. ($page + 1), true), 'next'); 326 } 327 328 $data['sort'] = $sort; 329 $data['order'] = $order; 330 $data['limit'] = $limit; 331 332 $data['continue'] = $this->url->link('common/home'); 333 334 $data['column_left'] = $this->load->controller('common/column_left'); 335 $data['column_right'] = $this->load->controller('common/column_right'); 336 $data['content_top'] = $this->load->controller('common/content_top'); 337 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 338 $data['footer'] = $this->load->controller('common/footer'); 339 $data['header'] = $this->load->controller('common/header'); 340 341 $this->response->setOutput($this->load->view('product/manufacturer_info', $data)); 342 } else { 343 $url = ''; 344 345 if (isset($this->request->get['manufacturer_id'])) { 346 $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; 347 } 348 349 if (isset($this->request->get['sort'])) { 350 $url .= '&sort=' . $this->request->get['sort']; 351 } 352 353 if (isset($this->request->get['order'])) { 354 $url .= '&order=' . $this->request->get['order']; 355 } 356 357 if (isset($this->request->get['page'])) { 358 $url .= '&page=' . $this->request->get['page']; 359 } 360 361 if (isset($this->request->get['limit'])) { 362 $url .= '&limit=' . $this->request->get['limit']; 363 } 364 365 $data['breadcrumbs'][] = array( 366 'text' => $this->language->get('text_error'), 367 'href' => $this->url->link('product/manufacturer/info', $url) 368 ); 369 370 $this->document->setTitle($this->language->get('text_error')); 371 372 $data['heading_title'] = $this->language->get('text_error'); 373 374 $data['text_error'] = $this->language->get('text_error'); 375 376 $data['continue'] = $this->url->link('common/home'); 377 378 $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found'); 379 380 $data['header'] = $this->load->controller('common/header'); 381 $data['footer'] = $this->load->controller('common/footer'); 382 $data['column_left'] = $this->load->controller('common/column_left'); 383 $data['column_right'] = $this->load->controller('common/column_right'); 384 $data['content_top'] = $this->load->controller('common/content_top'); 385 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 386 387 $this->response->setOutput($this->load->view('error/not_found', $data)); 388 } 389 } 390 }