Advertisement
Guest User

Untitled

a guest
Jul 12th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.44 KB | None | 0 0
  1. <?php
  2. class ControllerProductCategory extends Controller {  
  3.     public function index() {
  4.         $this->language->load('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['sort'])) {
  13.             $sort = $this->request->get['sort'];
  14.         } else {
  15.             $sort = 'p.price';
  16.         }
  17.  
  18.         if (isset($this->request->get['order'])) {
  19.             $order = $this->request->get['order'];
  20.         } else {
  21.             $order = 'DESC';
  22.         }
  23.        
  24.         if (isset($this->request->get['page'])) {
  25.             $page = $this->request->get['page'];
  26.         } else {
  27.             $page = 1;
  28.         }  
  29.                            
  30.         if (isset($this->request->get['limit'])) {
  31.             $limit = $this->request->get['limit'];
  32.         } else {
  33.             $limit = $this->config->get('config_catalog_limit');
  34.         }
  35.                    
  36.         $this->data['breadcrumbs'] = array();
  37.  
  38.         $this->data['breadcrumbs'][] = array(
  39.             'text'      => $this->language->get('text_home'),
  40.             'href'      => $this->url->link('common/home'),
  41.             'separator' => false
  42.         ); 
  43.            
  44.         if (isset($this->request->get['path'])) {
  45.             $path = '';
  46.        
  47.             $parts = explode('_', (string)$this->request->get['path']);
  48.        
  49.             foreach ($parts as $path_id) {
  50.                 if (!$path) {
  51.                     $path = $path_id;
  52.                 } else {
  53.                     $path .= '_' . $path_id;
  54.                 }
  55.                                    
  56.                 $category_info = $this->model_catalog_category->getCategory($path_id);
  57.                
  58.                 if ($category_info) {
  59.                     $this->data['breadcrumbs'][] = array(
  60.                         'text'      => $category_info['name'],
  61.                         'href'      => $this->url->link('product/category', 'path=' . $path),
  62.                         'separator' => $this->language->get('text_separator')
  63.                     );
  64.                 }
  65.             }      
  66.        
  67.             $category_id = array_pop($parts);
  68.         } else {
  69.             $category_id = 0;
  70.         }
  71.        
  72.         $category_info = $this->model_catalog_category->getCategory($category_id);
  73.    
  74.         if ($category_info) {
  75.             if ($category_info['seo_title']) {
  76.                 $this->document->setTitle($category_info['seo_title']);
  77.             } else {
  78.                 $this->document->setTitle($category_info['name']);
  79.             }
  80.  
  81.             $this->document->setDescription($category_info['meta_description']);
  82.             $this->document->setKeywords($category_info['meta_keyword']);
  83.            
  84.             $this->data['seo_h1'] = $category_info['seo_h1'];
  85.  
  86.             $this->data['heading_title'] = $category_info['name'];
  87.            
  88.             $this->data['text_refine'] = $this->language->get('text_refine');
  89.             $this->data['text_empty'] = $this->language->get('text_empty');        
  90.             $this->data['text_quantity'] = $this->language->get('text_quantity');
  91.             $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
  92.             $this->data['text_model'] = $this->language->get('text_model');
  93.             $this->data['text_price'] = $this->language->get('text_price');
  94.             $this->data['text_tax'] = $this->language->get('text_tax');
  95.             $this->data['text_points'] = $this->language->get('text_points');
  96.             $this->data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  97.             $this->data['text_display'] = $this->language->get('text_display');
  98.             $this->data['text_list'] = $this->language->get('text_list');
  99.             $this->data['text_grid'] = $this->language->get('text_grid');
  100.             $this->data['text_sort'] = $this->language->get('text_sort');
  101.             $this->data['text_limit'] = $this->language->get('text_limit');
  102.                    
  103.             $this->data['button_cart'] = $this->language->get('button_cart');
  104.             $this->data['button_wishlist'] = $this->language->get('button_wishlist');
  105.             $this->data['button_compare'] = $this->language->get('button_compare');
  106.             $this->data['button_continue'] = $this->language->get('button_continue');
  107.                    
  108.             if ($category_info['image']) {
  109.                 $this->data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
  110.             } else {
  111.                 $this->data['thumb'] = '';
  112.             }
  113.                                    
  114.             $this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  115.             $this->data['compare'] = $this->url->link('product/compare');
  116.            
  117.             $url = '';
  118.            
  119.             if (isset($this->request->get['sort'])) {
  120.                 $url .= '&sort=' . $this->request->get['sort'];
  121.             }  
  122.  
  123.             if (isset($this->request->get['order'])) {
  124.                 $url .= '&order=' . $this->request->get['order'];
  125.             }  
  126.            
  127.             if (isset($this->request->get['limit'])) {
  128.                 $url .= '&limit=' . $this->request->get['limit'];
  129.             }
  130.                                
  131.             $this->data['categories'] = array();
  132.            
  133.             $results = $this->model_catalog_category->getCategories($category_id);
  134.            
  135.             foreach ($results as $result) {
  136.                 $data = array(
  137.                     'filter_category_id'  => $result['category_id'],
  138.                     'filter_sub_category' => true  
  139.                 );
  140.                            
  141.                 $product_total = $this->model_catalog_product->getTotalProducts($data);
  142.                
  143.                 $this->data['categories'][] = array(
  144.                     'name'  => $result['name'] . ' (' . $product_total . ')',
  145.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
  146.                 );
  147.             }
  148.            
  149.             $this->data['products'] = array();
  150.            
  151.             $data = array(
  152.                 'filter_category_id' => $category_id,
  153.                 'sort'               => $sort,
  154.                 'order'              => $order,
  155.                 'start'              => ($page - 1) * $limit,
  156.                 'limit'              => $limit
  157.             );
  158.                    
  159.             $product_total = $this->model_catalog_product->getTotalProducts($data);
  160.            
  161.             $results = $this->model_catalog_product->getProducts($data);
  162.            
  163.             foreach ($results as $result) {
  164.                 if ($result['image']) {
  165.                     $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  166.                 } else {
  167.                     $image = false;
  168.                 }
  169.                
  170.                 if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  171.                     $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  172.                 } else {
  173.                     $price = false;
  174.                 }
  175.                
  176.                 if ((float)$result['special']) {
  177.                     $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  178.                 } else {
  179.                     $special = false;
  180.                 }  
  181.                
  182.                 if ($this->config->get('config_tax')) {
  183.                     $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
  184.                 } else {
  185.                     $tax = false;
  186.                 }              
  187.                
  188.                 if ($this->config->get('config_review_status')) {
  189.                     $rating = (int)$result['rating'];
  190.                 } else {
  191.                     $rating = false;
  192.                 }
  193.                                
  194.                 $this->data['products'][] = array(
  195.                     'product_id'  => $result['product_id'],
  196.                     'thumb'       => $image,
  197.                     'name'        => $result['name'],
  198.                     'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
  199.                     'price'       => $price,
  200.                     'special'     => $special,
  201.                     'tax'         => $tax,
  202.                     'rating'      => $result['rating'],
  203.                     'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  204.                     'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
  205.                 );
  206.             }
  207.            
  208.             $url = '';
  209.    
  210.             if (isset($this->request->get['limit'])) {
  211.                 $url .= '&limit=' . $this->request->get['limit'];
  212.             }
  213.                            
  214.             $this->data['sorts'] = array();
  215.            
  216.             $this->data['sorts'][] = array(
  217.                 'text'  => $this->language->get('text_default'),
  218.                 'value' => 'p.sort_order-ASC',
  219.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
  220.             );
  221.            
  222.             $this->data['sorts'][] = array(
  223.                 'text'  => $this->language->get('text_name_asc'),
  224.                 'value' => 'pd.name-ASC',
  225.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)
  226.             );
  227.  
  228.             $this->data['sorts'][] = array(
  229.                 'text'  => $this->language->get('text_name_desc'),
  230.                 'value' => 'pd.name-DESC',
  231.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)
  232.             );
  233.  
  234.             $this->data['sorts'][] = array(
  235.                 'text'  => $this->language->get('text_price_asc'),
  236.                 'value' => 'p.price-ASC',
  237.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)
  238.             );
  239.  
  240.             $this->data['sorts'][] = array(
  241.                 'text'  => $this->language->get('text_price_desc'),
  242.                 'value' => 'p.price-DESC',
  243.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)
  244.             );
  245.            
  246.             if ($this->config->get('config_review_status')) {
  247.                 $this->data['sorts'][] = array(
  248.                     'text'  => $this->language->get('text_rating_desc'),
  249.                     'value' => 'rating-DESC',
  250.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url)
  251.                 );
  252.                
  253.                 $this->data['sorts'][] = array(
  254.                     'text'  => $this->language->get('text_rating_asc'),
  255.                     'value' => 'rating-ASC',
  256.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url)
  257.                 );
  258.             }
  259.            
  260.             $this->data['sorts'][] = array(
  261.                 'text'  => $this->language->get('text_model_asc'),
  262.                 'value' => 'p.model-ASC',
  263.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)
  264.             );
  265.  
  266.             $this->data['sorts'][] = array(
  267.                 'text'  => $this->language->get('text_model_desc'),
  268.                 'value' => 'p.model-DESC',
  269.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
  270.             );
  271.            
  272.             $url = '';
  273.    
  274.             if (isset($this->request->get['sort'])) {
  275.                 $url .= '&sort=' . $this->request->get['sort'];
  276.             }  
  277.  
  278.             if (isset($this->request->get['order'])) {
  279.                 $url .= '&order=' . $this->request->get['order'];
  280.             }
  281.            
  282.             $this->data['limits'] = array();
  283.            
  284.             $this->data['limits'][] = array(
  285.                 'text'  => $this->config->get('config_catalog_limit'),
  286.                 'value' => $this->config->get('config_catalog_limit'),
  287.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $this->config->get('config_catalog_limit'))
  288.             );
  289.                        
  290.             $this->data['limits'][] = array(
  291.                 'text'  => 25,
  292.                 'value' => 25,
  293.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=25')
  294.             );
  295.            
  296.             $this->data['limits'][] = array(
  297.                 'text'  => 50,
  298.                 'value' => 50,
  299.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=50')
  300.             );
  301.  
  302.             $this->data['limits'][] = array(
  303.                 'text'  => 75,
  304.                 'value' => 75,
  305.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=75')
  306.             );
  307.            
  308.             $this->data['limits'][] = array(
  309.                 'text'  => 100,
  310.                 'value' => 100,
  311.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=100')
  312.             );
  313.                        
  314.             $url = '';
  315.    
  316.             if (isset($this->request->get['sort'])) {
  317.                 $url .= '&sort=' . $this->request->get['sort'];
  318.             }  
  319.  
  320.             if (isset($this->request->get['order'])) {
  321.                 $url .= '&order=' . $this->request->get['order'];
  322.             }
  323.    
  324.             if (isset($this->request->get['limit'])) {
  325.                 $url .= '&limit=' . $this->request->get['limit'];
  326.             }
  327.                    
  328.             $pagination = new Pagination();
  329.             $pagination->total = $product_total;
  330.             $pagination->page = $page;
  331.             $pagination->limit = $limit;
  332.             $pagination->text = $this->language->get('text_pagination');
  333.             $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
  334.        
  335.             $this->data['pagination'] = $pagination->render();
  336.        
  337.             $this->data['sort'] = $sort;
  338.             $this->data['order'] = $order;
  339.             $this->data['limit'] = $limit;
  340.        
  341.             $this->data['continue'] = $this->url->link('common/home');
  342.  
  343.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  344.                 $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
  345.             } else {
  346.                 $this->template = 'default/template/product/category.tpl';
  347.             }
  348.            
  349.             $this->children = array(
  350.                 'common/column_left',
  351.                 'common/column_right',
  352.                 'common/content_top',
  353.                 'common/content_bottom',
  354.                 'common/footer',
  355.                 'common/header'
  356.             );
  357.                
  358.             $this->response->setOutput($this->render());                                       
  359.         } else {
  360.             $url = '';
  361.            
  362.             if (isset($this->request->get['path'])) {
  363.                 $url .= '&path=' . $this->request->get['path'];
  364.             }
  365.                                    
  366.             if (isset($this->request->get['sort'])) {
  367.                 $url .= '&sort=' . $this->request->get['sort'];
  368.             }  
  369.  
  370.             if (isset($this->request->get['order'])) {
  371.                 $url .= '&order=' . $this->request->get['order'];
  372.             }
  373.                
  374.             if (isset($this->request->get['page'])) {
  375.                 $url .= '&page=' . $this->request->get['page'];
  376.             }
  377.                        
  378.             if (isset($this->request->get['limit'])) {
  379.                 $url .= '&limit=' . $this->request->get['limit'];
  380.             }
  381.                        
  382.             $this->data['breadcrumbs'][] = array(
  383.                 'text'      => $this->language->get('text_error'),
  384.                 'href'      => $this->url->link('product/category', $url),
  385.                 'separator' => $this->language->get('text_separator')
  386.             );
  387.                
  388.             $this->document->setTitle($this->language->get('text_error'));
  389.  
  390.             $this->data['heading_title'] = $this->language->get('text_error');
  391.  
  392.             $this->data['text_error'] = $this->language->get('text_error');
  393.  
  394.             $this->data['button_continue'] = $this->language->get('button_continue');
  395.  
  396.             $this->data['continue'] = $this->url->link('common/home');
  397.  
  398.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  399.                 $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  400.             } else {
  401.                 $this->template = 'default/template/error/not_found.tpl';
  402.             }
  403.            
  404.             $this->children = array(
  405.                 'common/column_left',
  406.                 'common/column_right',
  407.                 'common/content_top',
  408.                 'common/content_bottom',
  409.                 'common/footer',
  410.                 'common/header'
  411.             );
  412.                    
  413.             $this->response->setOutput($this->render());
  414.         }
  415.     }
  416. }
  417. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement