Advertisement
Guest User

Untitled

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