Advertisement
Guest User

Untitled

a guest
Nov 9th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.52 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.sort_order';
  16.         }
  17.  
  18.         if (isset($this->request->get['order'])) {
  19.             $order = $this->request->get['order'];
  20.         } else {
  21.             $order = 'ASC';
  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.  
  165.                 if ($result['image']) {
  166.                     $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  167.                 } else {
  168.                     $image = false;
  169.                 }
  170.  
  171.                 if ($result['image2']) {
  172.                     $image2 = $this->model_tool_image->resize($result['image2'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  173.                 } else {
  174.                     if (file_exists (DIR_IMAGE . 'no_image2.jpg')) {
  175.                     $image2 = $this->model_tool_image->resize('no_image2.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  176.                     } else {
  177.                     $image2 = false;
  178.                     }
  179.                 }
  180.  
  181.                 if ($result['image3']) {
  182.                     $image3 = $this->model_tool_image->resize($result['image3'], 60, 60);
  183.                 } else {
  184.                     if (file_exists (DIR_IMAGE . 'ico-artist.jpg')) {
  185.                     $image3 = $this->model_tool_image->resize('ico-artist.jpg', 60, 60);
  186.                     } else {
  187.                     $image3 = false;
  188.                     }
  189.                 }
  190.  
  191.  
  192.  
  193.                 if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  194.                     $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  195.                 } else {
  196.                     $price = false;
  197.                 }
  198.  
  199.                 if ((float)$result['special']) {
  200.                     $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  201.                 } else {
  202.                     $special = false;
  203.                 }
  204.  
  205.                 if ($this->config->get('config_tax')) {
  206.                     $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
  207.                 } else {
  208.                     $tax = false;
  209.                 }
  210.  
  211.                 if ($this->config->get('config_review_status')) {
  212.                     $rating = (int)$result['rating'];
  213.                 } else {
  214.                     $rating = false;
  215.                 }
  216.  
  217.                 $this->data['products'][] = array(
  218.  
  219.  
  220.             /////////////////////////////////////
  221.             $this->data['downloads'] = array();
  222.  
  223.             $results = $this->model_catalog_product->getDownloads($this->request->get['product_id']);
  224.  
  225.             foreach ($results as $result) {
  226.                 if (file_exists(DIR_DOWNLOAD . $result['filename'])) {
  227.                     $size = filesize(DIR_DOWNLOAD . $result['filename']);
  228.  
  229.                     $i = 0;
  230.  
  231.                     $suffix = array(
  232.                         'B',
  233.                         'KB',
  234.                         'MB',
  235.                         'GB',
  236.                         'TB',
  237.                         'PB',
  238.                         'EB',
  239.                         'ZB',
  240.                         'YB'
  241.                     );
  242.  
  243.                     while (($size / 1024) > 1) {
  244.                         $size = $size / 1024;
  245.                         $i++;
  246.                     }
  247.  
  248.                     $this->data['downloads'][] = array(
  249.                         'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  250.                         'name'       => $result['name'],
  251.                         'size'       => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
  252.                         'href'       => $this->url->link('product/product/download', 'product_id='. $this->request->get['product_id']. '&download_id=' . $result['download_id'])
  253.                     );
  254.                 }
  255.             }
  256.             ///////////////////////////////////////
  257.  
  258.  
  259.                     'product_id'  => $result['product_id'],
  260.                     'thumb'      => $image,
  261.                     'thumb2'     => $image2,
  262.                     'thumb3'     => $image3,
  263.                     'name'        => $result['name'],
  264.                     'artist'         => $result['artist'],
  265.                     'url_facebook'       => $result['url_facebook'],
  266.                     'description'=> html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
  267.                     'copyright'=> html_entity_decode($result['copyright'], ENT_QUOTES, 'UTF-8'),
  268.                     'price'       => $price,
  269.                     'special'     => $special,
  270.                     'tax'         => $tax,
  271.                     'rating'      => $result['rating'],
  272.                     'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  273.                     'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
  274.                 );
  275.             }
  276.  
  277.             $url = '';
  278.  
  279.             if (isset($this->request->get['limit'])) {
  280.                 $url .= '&limit=' . $this->request->get['limit'];
  281.             }
  282.  
  283.             $this->data['sorts'] = array();
  284.  
  285.             $this->data['sorts'][] = array(
  286.                 'text'  => $this->language->get('text_default'),
  287.                 'value' => 'p.sort_order-ASC',
  288.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
  289.             );
  290.  
  291.             $this->data['sorts'][] = array(
  292.                 'text'  => $this->language->get('text_name_asc'),
  293.                 'value' => 'pd.name-ASC',
  294.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)
  295.             );
  296.  
  297.             $this->data['sorts'][] = array(
  298.                 'text'  => $this->language->get('text_name_desc'),
  299.                 'value' => 'pd.name-DESC',
  300.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)
  301.             );
  302.  
  303.             $this->data['sorts'][] = array(
  304.                 'text'  => $this->language->get('text_price_asc'),
  305.                 'value' => 'p.price-ASC',
  306.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)
  307.             );
  308.  
  309.             $this->data['sorts'][] = array(
  310.                 'text'  => $this->language->get('text_price_desc'),
  311.                 'value' => 'p.price-DESC',
  312.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)
  313.             );
  314.  
  315.             if ($this->config->get('config_review_status')) {
  316.                 $this->data['sorts'][] = array(
  317.                     'text'  => $this->language->get('text_rating_desc'),
  318.                     'value' => 'rating-DESC',
  319.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url)
  320.                 );
  321.  
  322.                 $this->data['sorts'][] = array(
  323.                     'text'  => $this->language->get('text_rating_asc'),
  324.                     'value' => 'rating-ASC',
  325.                     'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url)
  326.                 );
  327.             }
  328.  
  329.             $this->data['sorts'][] = array(
  330.                 'text'  => $this->language->get('text_model_asc'),
  331.                 'value' => 'p.model-ASC',
  332.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)
  333.             );
  334.  
  335.             $this->data['sorts'][] = array(
  336.                 'text'  => $this->language->get('text_model_desc'),
  337.                 'value' => 'p.model-DESC',
  338.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
  339.             );
  340.  
  341.             $url = '';
  342.  
  343.             if (isset($this->request->get['sort'])) {
  344.                 $url .= '&sort=' . $this->request->get['sort'];
  345.             }
  346.  
  347.             if (isset($this->request->get['order'])) {
  348.                 $url .= '&order=' . $this->request->get['order'];
  349.             }
  350.  
  351.             $this->data['limits'] = array();
  352.  
  353.             $this->data['limits'][] = array(
  354.                 'text'  => $this->config->get('config_catalog_limit'),
  355.                 'value' => $this->config->get('config_catalog_limit'),
  356.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $this->config->get('config_catalog_limit'))
  357.             );
  358.  
  359.             $this->data['limits'][] = array(
  360.                 'text'  => 25,
  361.                 'value' => 25,
  362.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=25')
  363.             );
  364.  
  365.             $this->data['limits'][] = array(
  366.                 'text'  => 50,
  367.                 'value' => 50,
  368.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=50')
  369.             );
  370.  
  371.             $this->data['limits'][] = array(
  372.                 'text'  => 75,
  373.                 'value' => 75,
  374.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=75')
  375.             );
  376.  
  377.             $this->data['limits'][] = array(
  378.                 'text'  => 100,
  379.                 'value' => 100,
  380.                 'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=100')
  381.             );
  382.  
  383.             $url = '';
  384.  
  385.             if (isset($this->request->get['sort'])) {
  386.                 $url .= '&sort=' . $this->request->get['sort'];
  387.             }
  388.  
  389.             if (isset($this->request->get['order'])) {
  390.                 $url .= '&order=' . $this->request->get['order'];
  391.             }
  392.  
  393.             if (isset($this->request->get['limit'])) {
  394.                 $url .= '&limit=' . $this->request->get['limit'];
  395.             }
  396.  
  397.             $pagination = new Pagination();
  398.             $pagination->total = $product_total;
  399.             $pagination->page = $page;
  400.             $pagination->limit = $limit;
  401.             $pagination->text = $this->language->get('text_pagination');
  402.             $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
  403.  
  404.             $this->data['pagination'] = $pagination->render();
  405.  
  406.             $this->data['sort'] = $sort;
  407.             $this->data['order'] = $order;
  408.             $this->data['limit'] = $limit;
  409.  
  410.             $this->data['continue'] = $this->url->link('common/home');
  411.  
  412.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  413.                 $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
  414.             } else {
  415.                 $this->template = 'default/template/product/category.tpl';
  416.             }
  417.  
  418.             $this->children = array(
  419.                 'common/column_left',
  420.                 'common/column_right',
  421.                 'common/content_top',
  422.                 'common/content_bottom',
  423.                 'common/footer',
  424.                 'common/header'
  425.             );
  426.  
  427.             $this->response->setOutput($this->render());
  428.         } else {
  429.             $url = '';
  430.  
  431.             if (isset($this->request->get['path'])) {
  432.                 $url .= '&path=' . $this->request->get['path'];
  433.             }
  434.  
  435.             if (isset($this->request->get['sort'])) {
  436.                 $url .= '&sort=' . $this->request->get['sort'];
  437.             }
  438.  
  439.             if (isset($this->request->get['order'])) {
  440.                 $url .= '&order=' . $this->request->get['order'];
  441.             }
  442.  
  443.             if (isset($this->request->get['page'])) {
  444.                 $url .= '&page=' . $this->request->get['page'];
  445.             }
  446.  
  447.             if (isset($this->request->get['limit'])) {
  448.                 $url .= '&limit=' . $this->request->get['limit'];
  449.             }
  450.  
  451.             $this->data['breadcrumbs'][] = array(
  452.                 'text'      => $this->language->get('text_error'),
  453.                 'href'      => $this->url->link('product/category', $url),
  454.                 'separator' => $this->language->get('text_separator')
  455.             );
  456.  
  457.             $this->document->setTitle($this->language->get('text_error'));
  458.  
  459.             $this->data['heading_title'] = $this->language->get('text_error');
  460.  
  461.             $this->data['text_error'] = $this->language->get('text_error');
  462.  
  463.             $this->data['button_continue'] = $this->language->get('button_continue');
  464.  
  465.             $this->data['continue'] = $this->url->link('common/home');
  466.  
  467.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  468.                 $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  469.             } else {
  470.                 $this->template = 'default/template/error/not_found.tpl';
  471.             }
  472.  
  473.             $this->children = array(
  474.                 'common/column_left',
  475.                 'common/column_right',
  476.                 'common/content_top',
  477.                 'common/content_bottom',
  478.                 'common/footer',
  479.                 'common/header'
  480.             );
  481.  
  482.             $this->response->setOutput($this->render());
  483.         }
  484.     }
  485.  
  486.     ////////////////////////////////////////////////////////////////////////////////
  487.     public function download() {
  488.  
  489.         $this->load->model('catalog/product');
  490.  
  491.         if (isset($this->request->get['download_id'])) {
  492.             $download_id = $this->request->get['download_id'];
  493.         } else {
  494.             $download_id = 0;
  495.         }
  496.  
  497.         if (isset($this->request->get['product_id'])) {
  498.             $product_id = $this->request->get['product_id'];
  499.         } else {
  500.             $product_id = 0;
  501.         }
  502.  
  503.         $download_info = $this->model_catalog_product->getDownload($product_id, $download_id);
  504.  
  505.         if ($download_info) {
  506.             $file = DIR_DOWNLOAD . $download_info['filename'];
  507.             $mask = basename($download_info['mask']);
  508.  
  509.             if (!headers_sent()) {
  510.                 if (file_exists($file)) {
  511.                     header('Content-Description: File Transfer');
  512.                     header('Content-Type: application/octet-stream');
  513.                     header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
  514.                     header('Content-Transfer-Encoding: binary');
  515.                     header('Expires: 0');
  516.                     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  517.                     header('Pragma: public');
  518.                     header('Content-Length: ' . filesize($file));
  519.  
  520.                     readfile($file, 'rb');
  521.  
  522.                     //$this->model_account_download->updateRemaining($this->request->get['download_id']);
  523.  
  524.                     exit;
  525.                 } else {
  526.                     exit('Error: Could not find file ' . $file . '!');
  527.                 }
  528.             } else {
  529.                 exit('Error: Headers already sent out!');
  530.             }
  531.         } else {
  532.             $this->redirect(HTTP_SERVER . 'index.php?route=account/download');
  533.         }
  534.     }
  535.     ////////////////////////////////////////////////////////////////////////////////
  536.  
  537.     ////////////////////////////////////////////////////////////////////////////////
  538.     public function upload() {
  539.         $this->language->load('product/product');
  540.  
  541.         $json = array();
  542.  
  543.         if (!empty($this->request->files['file']['name'])) {
  544.             $filename = basename(preg_replace('/[^a-zA-Z0-9\.\-\s+]/', '', html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')));
  545.  
  546.             if ((strlen($filename) < 3) || (strlen($filename) > 64)) {
  547.                 $json['error'] = $this->language->get('error_filename');
  548.             }
  549.  
  550.             $allowed = array();
  551.  
  552.             $filetypes = explode(',', $this->config->get('config_upload_allowed'));
  553.  
  554.             foreach ($filetypes as $filetype) {
  555.                 $allowed[] = trim($filetype);
  556.             }
  557.  
  558.             if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  559.                 $json['error'] = $this->language->get('error_filetype');
  560.             }
  561.  
  562.             if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  563.                 $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  564.             }
  565.         } else {
  566.             $json['error'] = $this->language->get('error_upload');
  567.         }
  568.  
  569.         if (!$json) {
  570.             if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  571.                 $file = basename($filename) . '.' . md5(mt_rand());
  572.  
  573.                 // Hide the uploaded file name so people can not link to it directly.
  574.                 $json['file'] = $this->encryption->encrypt($file);
  575.  
  576.                 move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  577.             }
  578.  
  579.             $json['success'] = $this->language->get('text_upload');
  580.         }
  581.  
  582.         $this->response->setOutput(json_encode($json));
  583.     }
  584.     ////////////////////////////////////////////////////////////////////////////////
  585.  
  586. }
  587. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement