Advertisement
Guest User

Untitled

a guest
May 20th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.27 KB | None | 0 0
  1. <?php
  2. class ControllerProductCategory extends Controller {
  3.     public function index() {
  4.         $this->load->language('product/category');
  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['filter'])) {
  13.             $filter = $this->request->get['filter'];
  14.         } else {
  15.             $filter = '';
  16.         }
  17.  
  18.         if (isset($this->request->get['sort'])) {
  19.             $sort = $this->request->get['sort'];
  20.         } else {
  21.             $sort = 'p.sort_order';
  22.         }
  23.  
  24.         if (isset($this->request->get['order'])) {
  25.             $order = $this->request->get['order'];
  26.         } else {
  27.             $order = 'ASC';
  28.         }
  29.  
  30.         if (isset($this->request->get['page'])) {
  31.             $page = $this->request->get['page'];
  32.         } else {
  33.             $page = 1;
  34.         }
  35.  
  36.         if (isset($this->request->get['limit'])) {
  37.             $limit = (int)$this->request->get['limit'];
  38.         } else {
  39.             $limit = $this->config->get('config_product_limit');
  40.         }
  41.  
  42.         $data['breadcrumbs'] = array();
  43.  
  44.         $data['breadcrumbs'][] = array(
  45.             'text' => $this->language->get('text_home'),
  46.             'href' => $this->url->link('common/home')
  47.         );
  48.  
  49.         if (isset($this->request->get['path'])) {
  50.             $url = '';
  51.  
  52.             if (isset($this->request->get['sort'])) {
  53.                 $url .= '&sort=' . $this->request->get['sort'];
  54.             }
  55.  
  56.             if (isset($this->request->get['order'])) {
  57.                 $url .= '&order=' . $this->request->get['order'];
  58.             }
  59.  
  60.             if (isset($this->request->get['limit'])) {
  61.                 $url .= '&limit=' . $this->request->get['limit'];
  62.             }
  63.  
  64.             $path = '';
  65.  
  66.             $parts = explode('_', (string)$this->request->get['path']);
  67.  
  68.             $category_id = (int)array_pop($parts);
  69.  
  70.             foreach ($parts as $path_id) {
  71.                 if (!$path) {
  72.                     $path = (int)$path_id;
  73.                 } else {
  74.                     $path .= '_' . (int)$path_id;
  75.                 }
  76.  
  77.                 $category_info = $this->model_catalog_category->getCategory($path_id);
  78.  
  79.                 if ($category_info) {
  80.                     $data['breadcrumbs'][] = array(
  81.                         'text' => $category_info['name'],
  82.                         'href' => $this->url->link('product/category', 'path=' . $path . $url)
  83.                     );
  84.                 }
  85.             }
  86.         } else {
  87.             $category_id = 0;
  88.         }
  89.  
  90.         $category_info = $this->model_catalog_category->getCategory($category_id);
  91.  
  92.         if ($category_info) {
  93.  
  94.             if ($category_info['meta_title']) {
  95.                 $this->document->setTitle($category_info['meta_title']);
  96.             } else {
  97.                 $this->document->setTitle($category_info['name']);
  98.             }
  99.  
  100.             $this->document->setDescription($category_info['meta_description']);
  101.             $this->document->setKeywords($category_info['meta_keyword']);
  102.  
  103.             if ($category_info['meta_h1']) {
  104.                 $data['heading_title'] = $category_info['meta_h1'];
  105.             } else {
  106.                 $data['heading_title'] = $category_info['name'];
  107.             }
  108.  
  109.             $data['text_refine'] = $this->language->get('text_refine');
  110.             $data['text_empty'] = $this->language->get('text_empty');
  111.             $data['text_quantity'] = $this->language->get('text_quantity');
  112.             $data['text_manufacturer'] = $this->language->get('text_manufacturer');
  113.             $data['text_model'] = $this->language->get('text_model');
  114.             $data['text_price'] = $this->language->get('text_price');
  115.             $data['text_tax'] = $this->language->get('text_tax');
  116.             $data['text_points'] = $this->language->get('text_points');
  117.             $data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  118.             $data['text_sort'] = $this->language->get('text_sort');
  119.             $data['text_limit'] = $this->language->get('text_limit');
  120.  
  121.             $data['button_cart'] = $this->language->get('button_cart');
  122.             $data['button_wishlist'] = $this->language->get('button_wishlist');
  123.             $data['button_compare'] = $this->language->get('button_compare');
  124.             $data['button_continue'] = $this->language->get('button_continue');
  125.             $data['button_list'] = $this->language->get('button_list');
  126.             $data['button_grid'] = $this->language->get('button_grid');
  127.  
  128.             // Set the last category breadcrumb
  129.             $data['breadcrumbs'][] = array(
  130.                 'text' => $category_info['name'],
  131.                 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'])
  132.             );
  133.  
  134.             if ($category_info['image']) {
  135.                 $data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
  136.             } else {
  137.                 $data['thumb'] = '';
  138.             }
  139.            
  140.             $data['category_banner'] = html_entity_decode($category_info['category_banner'], ENT_QUOTES, 'UTF-8');
  141.             $data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  142.             $data['compare'] = $this->url->link('product/compare');
  143.  
  144.             $url = '';
  145.  
  146.             if (isset($this->request->get['filter'])) {
  147.                 $url .= '&filter=' . $this->request->get['filter'];
  148.             }
  149.  
  150.             if (isset($this->request->get['sort'])) {
  151.                 $url .= '&sort=' . $this->request->get['sort'];
  152.             }
  153.  
  154.             if (isset($this->request->get['order'])) {
  155.                 $url .= '&order=' . $this->request->get['order'];
  156.             }
  157.  
  158.             if (isset($this->request->get['limit'])) {
  159.                 $url .= '&limit=' . $this->request->get['limit'];
  160.             }
  161.  
  162.             $data['categories'] = array();
  163.  
  164.             $results = $this->model_catalog_category->getCategories($category_id);
  165.  
  166.             foreach ($results as $result) {
  167.                 $filter_data = array(
  168.                     'filter_category_id'  => $result['category_id'],
  169.                     'filter_sub_category' => true
  170.                 );
  171.  
  172.                 $data['categories'][] = array(
  173.                     'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
  174.                     'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
  175.                 );
  176.             }
  177.  
  178.             $data['products'] = array();
  179.  
  180.             $filter_data = array(
  181.                 'filter_category_id' => $category_id,
  182.                 'filter_filter'      => $filter,
  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('config_image_product_width'), $this->config->get('config_image_product_height'));
  196.                 } else {
  197.                     $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  198.                 }
  199.  
  200.                 if (($this->config->get('config_customer_price') && $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')));
  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')));
  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']);
  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.                     'category_banner' => utf8_substr(strip_tags(html_entity_decode($result['category_banner'], ENT_QUOTES, 'UTF-8')), 0, 300) . '..',
  229.                     'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
  230.                     'price'       => $price,
  231.                     'special'     => $special,
  232.                     'tax'         => $tax,
  233.                     'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
  234.                     'rating'      => $result['rating'],
  235.                     'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url),
  236.                     'manufact'    => $result['manufacturer']
  237.                 );
  238.             }
  239.  
  240.             $url = '';
  241.  
  242.             if (isset($this->request->get['filter'])) {
  243.                 $url .= '&filter=' . $this->request->get['filter'];
  244.             }
  245.  
  246.             if (isset($this->request->get['limit'])) {
  247.                 $url .= '&limit=' . $this->request->get['limit'];
  248.             }
  249.  
  250.             $data['sorts'] = array();
  251.  
  252.             $data['sorts'][] = array(
  253.                 'text'  => $this->language->get('text_default'),
  254.                 'value' => 'p.sort_order-ASC',
  255.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
  256.             );
  257.  
  258.             $data['sorts'][] = array(
  259.                 'text'  => $this->language->get('text_name_asc'),
  260.                 'value' => 'pd.name-ASC',
  261.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)
  262.             );
  263.  
  264.             $data['sorts'][] = array(
  265.                 'text'  => $this->language->get('text_name_desc'),
  266.                 'value' => 'pd.name-DESC',
  267.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)
  268.             );
  269.  
  270.             $data['sorts'][] = array(
  271.                 'text'  => $this->language->get('text_price_asc'),
  272.                 'value' => 'p.price-ASC',
  273.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)
  274.             );
  275.  
  276.             $data['sorts'][] = array(
  277.                 'text'  => $this->language->get('text_price_desc'),
  278.                 'value' => 'p.price-DESC',
  279.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)
  280.             );
  281.  
  282.             if ($this->config->get('config_review_status')) {
  283.                 $data['sorts'][] = array(
  284.                     'text'  => $this->language->get('text_rating_desc'),
  285.                     'value' => 'rating-DESC',
  286.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url)
  287.                 );
  288.  
  289.                 $data['sorts'][] = array(
  290.                     'text'  => $this->language->get('text_rating_asc'),
  291.                     'value' => 'rating-ASC',
  292.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url)
  293.                 );
  294.             }
  295.  
  296.             $data['sorts'][] = array(
  297.                 'text'  => $this->language->get('text_model_asc'),
  298.                 'value' => 'p.model-ASC',
  299.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)
  300.             );
  301.  
  302.             $data['sorts'][] = array(
  303.                 'text'  => $this->language->get('text_model_desc'),
  304.                 'value' => 'p.model-DESC',
  305.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
  306.             );
  307.  
  308.             $url = '';
  309.  
  310.             if (isset($this->request->get['filter'])) {
  311.                 $url .= '&filter=' . $this->request->get['filter'];
  312.             }
  313.  
  314.             if (isset($this->request->get['sort'])) {
  315.                 $url .= '&sort=' . $this->request->get['sort'];
  316.             }
  317.  
  318.             if (isset($this->request->get['order'])) {
  319.                 $url .= '&order=' . $this->request->get['order'];
  320.             }
  321.  
  322.             $data['limits'] = array();
  323.  
  324.             $limits = array_unique(array($this->config->get('config_product_limit'), 25, 50, 75, 100));
  325.  
  326.             sort($limits);
  327.  
  328.             foreach($limits as $value) {
  329.                 $data['limits'][] = array(
  330.                     'text'  => $value,
  331.                     'value' => $value,
  332.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $value)
  333.                 );
  334.             }
  335.  
  336.             $url = '';
  337.  
  338.             if (isset($this->request->get['filter'])) {
  339.                 $url .= '&filter=' . $this->request->get['filter'];
  340.             }
  341.  
  342.             if (isset($this->request->get['sort'])) {
  343.                 $url .= '&sort=' . $this->request->get['sort'];
  344.             }
  345.  
  346.             if (isset($this->request->get['order'])) {
  347.                 $url .= '&order=' . $this->request->get['order'];
  348.             }
  349.  
  350.             if (isset($this->request->get['limit'])) {
  351.                 $url .= '&limit=' . $this->request->get['limit'];
  352.             }
  353.  
  354.             $pagination = new Pagination();
  355.             $pagination->total = $product_total;
  356.             $pagination->page = $page;
  357.             $pagination->limit = $limit;
  358.             $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
  359.  
  360.             $data['pagination'] = $pagination->render();
  361.  
  362.             $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));
  363.  
  364.             // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
  365.             if ($page == 1) {
  366.                 $this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], 'SSL'), 'canonical');
  367.             } elseif ($page == 2) {
  368.                 $this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], 'SSL'), 'prev');
  369.             } else {
  370.                 $this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page - 1), 'SSL'), 'prev');
  371.             }
  372.  
  373.             if ($limit && ceil($product_total / $limit) > $page) {
  374.                 $this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1), 'SSL'), 'next');
  375.             }
  376.  
  377.             $data['sort'] = $sort;
  378.             $data['order'] = $order;
  379.             $data['limit'] = $limit;
  380.  
  381.             $data['continue'] = $this->url->link('common/home');
  382.  
  383.             $data['column_left'] = $this->load->controller('common/column_left');
  384.             $data['column_right'] = $this->load->controller('common/column_right');
  385.             $data['content_top'] = $this->load->controller('common/content_top');
  386.             $data['content_bottom'] = $this->load->controller('common/content_bottom');
  387.             $data['footer'] = $this->load->controller('common/footer');
  388.             $data['header'] = $this->load->controller('common/header');
  389.  
  390.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  391.                 $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));
  392.             } else {
  393.                 $this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
  394.             }
  395.         } else {
  396.             $url = '';
  397.  
  398.             if (isset($this->request->get['path'])) {
  399.                 $url .= '&path=' . $this->request->get['path'];
  400.             }
  401.  
  402.             if (isset($this->request->get['filter'])) {
  403.                 $url .= '&filter=' . $this->request->get['filter'];
  404.             }
  405.  
  406.             if (isset($this->request->get['sort'])) {
  407.                 $url .= '&sort=' . $this->request->get['sort'];
  408.             }
  409.  
  410.             if (isset($this->request->get['order'])) {
  411.                 $url .= '&order=' . $this->request->get['order'];
  412.             }
  413.  
  414.             if (isset($this->request->get['page'])) {
  415.                 $url .= '&page=' . $this->request->get['page'];
  416.             }
  417.  
  418.             if (isset($this->request->get['limit'])) {
  419.                 $url .= '&limit=' . $this->request->get['limit'];
  420.             }
  421.  
  422.             $data['breadcrumbs'][] = array(
  423.                 'text' => $this->language->get('text_error'),
  424.                 'href' => $this->url->link('product/category', $url)
  425.             );
  426.  
  427.             $this->document->setTitle($this->language->get('text_error'));
  428.  
  429.             $data['heading_title'] = $this->language->get('text_error');
  430.  
  431.             $data['text_error'] = $this->language->get('text_error');
  432.  
  433.             $data['button_continue'] = $this->language->get('button_continue');
  434.  
  435.             $data['continue'] = $this->url->link('common/home');
  436.  
  437.             $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
  438.  
  439.             $data['column_left'] = $this->load->controller('common/column_left');
  440.             $data['column_right'] = $this->load->controller('common/column_right');
  441.             $data['content_top'] = $this->load->controller('common/content_top');
  442.             $data['content_bottom'] = $this->load->controller('common/content_bottom');
  443.             $data['footer'] = $this->load->controller('common/footer');
  444.             $data['header'] = $this->load->controller('common/header');
  445.  
  446.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  447.                 $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/error/not_found.tpl', $data));
  448.             } else {
  449.                 $this->response->setOutput($this->load->view('default/template/error/not_found.tpl', $data));
  450.             }
  451.         }
  452.     }
  453. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement