Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 33.44 KB | None | 0 0
  1. <?php
  2.  
  3. class ControllerProductProduct extends Controller {
  4.     private $error = array();
  5.  
  6.     public function index() {
  7.  
  8.         $this->document->addStyle('catalog/view/javascript/jquery/owl-carousel/owl.carousel.css');
  9.         $this->document->addScript('catalog/view/javascript/jquery/owl-carousel/owl.carousel.min.js');
  10.         $this->document->addScript('catalog/view/javascript/jquery/jquery.maskedinput-1.3.min.js');
  11.         $this->document->addStyle('catalog/view/javascript/jquery/select/css/bootstrap-select.css');
  12.         $this->document->addScript('catalog/view/javascript/jquery/select/js/bootstrap-select.js');
  13.  
  14.         $data = array_merge(isset($data) ? $data : array(), $this->load->language('product/product'));
  15.  
  16.         $data['config_template'] = $this->config->get('config_template');
  17.         $data['config_telephone_mask'] = $this->config->get("config_telephone_mask");
  18.  
  19.         if ($this->customer->isLogged()) {
  20.             $data['customer'] = array(
  21.                 "name" => $this->customer->getFirstName(),
  22.                 "email" => $this->customer->getEmail(),
  23.                 "phone" => $this->customer->getTelephone()
  24.             );
  25.         } else {
  26.             $data['customer'] = array(
  27.                 "name" => '',
  28.                 "email" => '',
  29.                 "phone" => ''
  30.             );
  31.         }
  32.  
  33.         $data['breadcrumbs'] = array();
  34.  
  35.         $data['breadcrumbs'][] = array(
  36.             'text' => $this->language->get('text_home'),
  37.             'href' => $this->url->link('common/home')
  38.         );
  39.  
  40.         $this->load->model('catalog/category');
  41.  
  42.         if (isset($this->request->get['path'])) {
  43.             $path = '';
  44.  
  45.             $parts = explode('_', (string)$this->request->get['path']);
  46.  
  47.             $category_id = (int)array_pop($parts);
  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.                     $data['breadcrumbs'][] = array(
  60.                         'text' => $category_info['name'],
  61.                         'href' => $this->url->link('product/category', 'path=' . $path)
  62.                     );
  63.                 }
  64.             }
  65.  
  66.             // Set the last category breadcrumb
  67.             $category_info = $this->model_catalog_category->getCategory($category_id);
  68.  
  69.             if ($category_info) {
  70.                 $url = '';
  71.  
  72.                 if (isset($this->request->get['sort'])) {
  73.                     $url .= '&sort=' . $this->request->get['sort'];
  74.                 }
  75.  
  76.                 if (isset($this->request->get['order'])) {
  77.                     $url .= '&order=' . $this->request->get['order'];
  78.                 }
  79.  
  80.                 if (isset($this->request->get['page'])) {
  81.                     $url .= '&page=' . $this->request->get['page'];
  82.                 }
  83.  
  84.                 if (isset($this->request->get['limit'])) {
  85.                     $url .= '&limit=' . $this->request->get['limit'];
  86.                 }
  87.  
  88.                 $data['breadcrumbs'][] = array(
  89.                     'text' => $category_info['name'],
  90.                     'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url)
  91.                 );
  92.             }
  93.         }
  94.  
  95.         $this->load->model('catalog/manufacturer');
  96.  
  97.         if (isset($this->request->get['manufacturer_id'])) {
  98.             $data['breadcrumbs'][] = array(
  99.                 'text' => $this->language->get('text_brand'),
  100.                 'href' => $this->url->link('product/manufacturer')
  101.             );
  102.  
  103.             $url = '';
  104.  
  105.             if (isset($this->request->get['sort'])) {
  106.                 $url .= '&sort=' . $this->request->get['sort'];
  107.             }
  108.  
  109.             if (isset($this->request->get['order'])) {
  110.                 $url .= '&order=' . $this->request->get['order'];
  111.             }
  112.  
  113.             if (isset($this->request->get['page'])) {
  114.                 $url .= '&page=' . $this->request->get['page'];
  115.             }
  116.  
  117.             if (isset($this->request->get['limit'])) {
  118.                 $url .= '&limit=' . $this->request->get['limit'];
  119.             }
  120.  
  121.             $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
  122.  
  123.             if ($manufacturer_info) {
  124.                 $data['breadcrumbs'][] = array(
  125.                     'text' => $manufacturer_info['name'],
  126.                     'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
  127.                 );
  128.             }
  129.         }
  130.  
  131.         if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
  132.             $url = '';
  133.  
  134.             if (isset($this->request->get['search'])) {
  135.                 $url .= '&search=' . $this->request->get['search'];
  136.             }
  137.  
  138.             if (isset($this->request->get['tag'])) {
  139.                 $url .= '&tag=' . $this->request->get['tag'];
  140.             }
  141.  
  142.             if (isset($this->request->get['description'])) {
  143.                 $url .= '&description=' . $this->request->get['description'];
  144.             }
  145.  
  146.             if (isset($this->request->get['category_id'])) {
  147.                 $url .= '&category_id=' . $this->request->get['category_id'];
  148.             }
  149.  
  150.             if (isset($this->request->get['sub_category'])) {
  151.                 $url .= '&sub_category=' . $this->request->get['sub_category'];
  152.             }
  153.  
  154.             if (isset($this->request->get['sort'])) {
  155.                 $url .= '&sort=' . $this->request->get['sort'];
  156.             }
  157.  
  158.             if (isset($this->request->get['order'])) {
  159.                 $url .= '&order=' . $this->request->get['order'];
  160.             }
  161.  
  162.             if (isset($this->request->get['page'])) {
  163.                 $url .= '&page=' . $this->request->get['page'];
  164.             }
  165.  
  166.             if (isset($this->request->get['limit'])) {
  167.                 $url .= '&limit=' . $this->request->get['limit'];
  168.             }
  169.  
  170.             $data['breadcrumbs'][] = array(
  171.                 'text' => $this->language->get('text_search'),
  172.                 'href' => $this->url->link('product/search', $url)
  173.             );
  174.         }
  175.  
  176.         if (isset($this->request->get['product_id'])) {
  177.             $product_id = (int)$this->request->get['product_id'];
  178.         } else {
  179.             $product_id = 0;
  180.         }
  181.  
  182.         $this->load->model('catalog/product');
  183.  
  184.         $product_info = $this->model_catalog_product->getProduct($product_id);
  185.  
  186.         if ($product_info) {
  187.             $url = '';
  188.  
  189.             if (isset($this->request->get['path'])) {
  190.                 $url .= '&path=' . $this->request->get['path'];
  191.             }
  192.  
  193.             if (isset($this->request->get['filter'])) {
  194.                 $url .= '&filter=' . $this->request->get['filter'];
  195.             }
  196.  
  197.             if (isset($this->request->get['manufacturer_id'])) {
  198.                 $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  199.             }
  200.  
  201.             if (isset($this->request->get['search'])) {
  202.                 $url .= '&search=' . $this->request->get['search'];
  203.             }
  204.  
  205.             if (isset($this->request->get['tag'])) {
  206.                 $url .= '&tag=' . $this->request->get['tag'];
  207.             }
  208.  
  209.             if (isset($this->request->get['description'])) {
  210.                 $url .= '&description=' . $this->request->get['description'];
  211.             }
  212.  
  213.             if (isset($this->request->get['category_id'])) {
  214.                 $url .= '&category_id=' . $this->request->get['category_id'];
  215.             }
  216.  
  217.             if (isset($this->request->get['sub_category'])) {
  218.                 $url .= '&sub_category=' . $this->request->get['sub_category'];
  219.             }
  220.  
  221.             if (isset($this->request->get['sort'])) {
  222.                 $url .= '&sort=' . $this->request->get['sort'];
  223.             }
  224.  
  225.             if (isset($this->request->get['order'])) {
  226.                 $url .= '&order=' . $this->request->get['order'];
  227.             }
  228.  
  229.             if (isset($this->request->get['page'])) {
  230.                 $url .= '&page=' . $this->request->get['page'];
  231.             }
  232.  
  233.             if (isset($this->request->get['limit'])) {
  234.                 $url .= '&limit=' . $this->request->get['limit'];
  235.             }
  236.  
  237.             $data['breadcrumbs'][] = array(
  238.                 'text' => $product_info['name'],
  239.                 'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id'])
  240.             );
  241.  
  242.             $this->document->setTitle($product_info['meta_title']);
  243.             $this->document->setDescription($product_info['meta_description']);
  244.             $this->document->setKeywords($product_info['meta_keyword']);
  245.             $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
  246.             $this->document->addScript('catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js');
  247.             $this->document->addStyle('catalog/view/javascript/jquery/magnific/magnific-popup.css');
  248.             $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
  249.             $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
  250.             $this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
  251.  
  252.             $data['heading_title'] = $product_info['name'];
  253.             $data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
  254.             $data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
  255.  
  256.             $this->load->model('catalog/review');
  257.             $data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
  258.  
  259.             $data['product_id'] = (int)$this->request->get['product_id'];
  260.             $data['manufacturer'] = $product_info['manufacturer'];
  261.             $data['manufacturers'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']);
  262.             $data['model'] = $product_info['model'];
  263.             $data['reward'] = $product_info['reward'];
  264.             $data['points'] = $product_info['points'];
  265.             $data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
  266.  
  267.             if ($product_info['quantity'] <= 0) {
  268.                 $data['stock'] = $product_info['stock_status'];
  269.             } elseif ($this->config->get('config_stock_display')) {
  270.                 $data['stock'] = $product_info['quantity'];
  271.             } else {
  272.                 $data['stock'] = $this->language->get('text_instock');
  273.             }
  274.  
  275.             $this->load->model('tool/image');
  276.  
  277.             if ($product_info['image']) {
  278.                 $data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
  279.             } else {
  280.                 $data['popup'] = '';
  281.             }
  282.  
  283.             if ($product_info['image']) {
  284.                 $data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
  285.             } else {
  286.                 $data['thumb'] = '';
  287.             }
  288.  
  289.             $data['images'] = array();
  290.  
  291.             $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  292.  
  293.             foreach ($results as $result) {
  294.                 $data['images'][] = array(
  295.                     'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
  296.                     'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
  297.                 );
  298.             }
  299.  
  300.             if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  301.                 $data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  302.             } else {
  303.                 $data['price'] = false;
  304.             }
  305.  
  306.             if ((float)$product_info['special']) {
  307.                 $data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  308.             } else {
  309.                 $data['special'] = false;
  310.             }
  311.  
  312.             if ($this->config->get('config_tax')) {
  313.                 $data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']);
  314.             } else {
  315.                 $data['tax'] = false;
  316.             }
  317.  
  318.             $discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  319.  
  320.             $data['discounts'] = array();
  321.  
  322.             foreach ($discounts as $discount) {
  323.                 $data['discounts'][] = array(
  324.                     'quantity' => $discount['quantity'],
  325.                     'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
  326.                 );
  327.             }
  328.  
  329.             $data['options'] = array();
  330.  
  331.             foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
  332.                 $product_option_value_data = array();
  333.  
  334.                 foreach ($option['product_option_value'] as $option_value) {
  335.                     if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
  336.  
  337.                         if ($option_value['price_prefix'] == '+') {
  338.                             $option_value['price'] = $product_info['price'] + $option_value['price'];
  339.                         } else {
  340.                             $option_value['price'] = $product_info['price'] - $option_value['price'];
  341.                         }
  342.                         if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
  343.                             $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false));
  344.                         } else {
  345.                             $price = false;
  346.                         }
  347.  
  348.  
  349.                         if ($option_value['value_image']) {
  350.                             $popup = $this->model_tool_image->resize($option_value['value_image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
  351.                             $thumb = $this->model_tool_image->resize($option_value['value_image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
  352.                         } else {
  353.                             $popup = $thumb = '';
  354.                         }
  355.  
  356.                         $product_option_value_data[] = array(
  357.                             'product_option_value_id' => $option_value['product_option_value_id'],
  358.                             'option_value_id' => $option_value['option_value_id'],
  359.                             'name' => $option_value['name'],
  360.                             'value_image_thumb' => $thumb,
  361.                             'value_image_popup' => $popup,
  362.                             'image' => $this->model_tool_image->resize($option_value['image'], 78, 78),
  363.                             'price' => $price,
  364.                             'price_prefix' => $option_value['price_prefix']
  365.                         );
  366.                     }
  367.                 }
  368.  
  369.                 $data['options'][] = array(
  370.                     'product_option_id' => $option['product_option_id'],
  371.                     'product_option_value' => $product_option_value_data,
  372.                     'option_id' => $option['option_id'],
  373.                     'name' => $option['name'],
  374.                     'type' => $option['type'],
  375.                     'special_type' => $option['special_type'],
  376.                     'value' => $option['value'],
  377.                     'required' => $option['required']
  378.                 );
  379.             }
  380.  
  381.             if ($product_info['minimum']) {
  382.                 $data['minimum'] = $product_info['minimum'];
  383.             } else {
  384.                 $data['minimum'] = 1;
  385.             }
  386.  
  387.             $data['review_status'] = $this->config->get('config_review_status');
  388.  
  389.             if ($this->config->get('config_review_guest') || $this->customer->isLogged()) {
  390.                 $data['review_guest'] = true;
  391.             } else {
  392.                 $data['review_guest'] = false;
  393.             }
  394.  
  395.             if ($this->customer->isLogged()) {
  396.                 $data['customer_name'] = $this->customer->getFirstName() . '&nbsp;' . $this->customer->getLastName();
  397.             } else {
  398.                 $data['customer_name'] = '';
  399.             }
  400.  
  401.             $data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
  402.             $data['rating'] = (int)$product_info['rating'];
  403.  
  404.             // Captcha
  405.             if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
  406.                 $data['captcha'] = $this->load->controller('captcha/' . $this->config->get('config_captcha'));
  407.             } else {
  408.                 $data['captcha'] = '';
  409.             }
  410.  
  411.             $data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
  412.  
  413.             $data['products'] = array();
  414.  
  415.             $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  416.  
  417.             foreach ($results as $result) {
  418.                 if ($result['image']) {
  419.                     $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
  420.                 } else {
  421.                     $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
  422.                 }
  423.  
  424.                 if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  425.                     $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  426.                 } else {
  427.                     $price = false;
  428.                 }
  429.  
  430.                 if ((float)$result['special']) {
  431.                     $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  432.                 } else {
  433.                     $special = false;
  434.                 }
  435.  
  436.                 if ($this->config->get('config_tax')) {
  437.                     $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
  438.                 } else {
  439.                     $tax = false;
  440.                 }
  441.  
  442.                 if ($this->config->get('config_review_status')) {
  443.                     $rating = (int)$result['rating'];
  444.                 } else {
  445.                     $rating = false;
  446.                 }
  447.  
  448.                 $data['products'][] = array(
  449.                     'product_id' => $result['product_id'],
  450.                     'thumb' => $image,
  451.                     'name' => $result['name'],
  452.                     'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
  453.                     'price' => $price,
  454.                     'special' => $special,
  455.                     'tax' => $tax,
  456.                     'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
  457.                     'rating' => $rating,
  458.                     'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
  459.                 );
  460.             }
  461.  
  462.             $data['tags'] = array();
  463.  
  464.             if ($product_info['tag']) {
  465.                 $tags = explode(',', $product_info['tag']);
  466.  
  467.                 foreach ($tags as $tag) {
  468.                     $data['tags'][] = array(
  469.                         'tag' => trim($tag),
  470.                         'href' => $this->url->link('product/search', 'tag=' . trim($tag))
  471.                     );
  472.                 }
  473.             }
  474.  
  475.             $data['recurrings'] = $this->model_catalog_product->getProfiles($this->request->get['product_id']);
  476.  
  477.             $this->model_catalog_product->updateViewed($this->request->get['product_id']);
  478.  
  479.             $data['column_left'] = $this->load->controller('common/column_left');
  480.             $data['column_right'] = $this->load->controller('common/column_right');
  481.             $data['content_top'] = $this->load->controller('common/content_top');
  482.             $data['content_bottom'] = $this->load->controller('common/content_bottom');
  483.             $data['footer'] = $this->load->controller('common/footer');
  484.             $data['header'] = $this->load->controller('common/header');
  485.  
  486.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
  487.                 $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data));
  488.             } else {
  489.                 $this->response->setOutput($this->load->view('default/template/product/product.tpl', $data));
  490.             }
  491.         } else {
  492.             $url = '';
  493.  
  494.             if (isset($this->request->get['path'])) {
  495.                 $url .= '&path=' . $this->request->get['path'];
  496.             }
  497.  
  498.             if (isset($this->request->get['filter'])) {
  499.                 $url .= '&filter=' . $this->request->get['filter'];
  500.             }
  501.  
  502.             if (isset($this->request->get['manufacturer_id'])) {
  503.                 $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  504.             }
  505.  
  506.             if (isset($this->request->get['search'])) {
  507.                 $url .= '&search=' . $this->request->get['search'];
  508.             }
  509.  
  510.             if (isset($this->request->get['tag'])) {
  511.                 $url .= '&tag=' . $this->request->get['tag'];
  512.             }
  513.  
  514.             if (isset($this->request->get['description'])) {
  515.                 $url .= '&description=' . $this->request->get['description'];
  516.             }
  517.  
  518.             if (isset($this->request->get['category_id'])) {
  519.                 $url .= '&category_id=' . $this->request->get['category_id'];
  520.             }
  521.  
  522.             if (isset($this->request->get['sub_category'])) {
  523.                 $url .= '&sub_category=' . $this->request->get['sub_category'];
  524.             }
  525.  
  526.             if (isset($this->request->get['sort'])) {
  527.                 $url .= '&sort=' . $this->request->get['sort'];
  528.             }
  529.  
  530.             if (isset($this->request->get['order'])) {
  531.                 $url .= '&order=' . $this->request->get['order'];
  532.             }
  533.  
  534.             if (isset($this->request->get['page'])) {
  535.                 $url .= '&page=' . $this->request->get['page'];
  536.             }
  537.  
  538.             if (isset($this->request->get['limit'])) {
  539.                 $url .= '&limit=' . $this->request->get['limit'];
  540.             }
  541.  
  542.             $data['breadcrumbs'][] = array(
  543.                 'text' => $this->language->get('text_error'),
  544.                 'href' => $this->url->link('product/product', $url . '&product_id=' . $product_id)
  545.             );
  546.  
  547.             $this->document->setTitle($this->language->get('text_error'));
  548.  
  549.  
  550.             $data['continue'] = $this->url->link('common/home');
  551.  
  552.             $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
  553.  
  554.             $data['column_left'] = $this->load->controller('common/column_left');
  555.             $data['column_right'] = $this->load->controller('common/column_right');
  556.             $data['content_top'] = $this->load->controller('common/content_top');
  557.             $data['content_bottom'] = $this->load->controller('common/content_bottom');
  558.             $data['footer'] = $this->load->controller('common/footer');
  559.             $data['header'] = $this->load->controller('common/header');
  560.  
  561.             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  562.                 $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/error/not_found.tpl', $data));
  563.             } else {
  564.                 $this->response->setOutput($this->load->view('default/template/error/not_found.tpl', $data));
  565.             }
  566.         }
  567.     }
  568.  
  569.     public function review() {
  570.  
  571.         $data = array_merge(isset($data) ? $data : array(), $this->load->language('product/product'));
  572.  
  573.         $this->load->model('catalog/review');
  574.  
  575.         if (isset($this->request->get['page'])) {
  576.             $page = $this->request->get['page'];
  577.         } else {
  578.             $page = 1;
  579.         }
  580.  
  581.         $data['reviews'] = array();
  582.  
  583.         $review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
  584.  
  585.         $results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5);
  586.  
  587.         foreach ($results as $result) {
  588.             $data['reviews'][] = array(
  589.                 'author' => $result['author'],
  590.                 'text' => nl2br($result['text']),
  591.                 'rating' => (int)$result['rating'],
  592.                 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  593.             );
  594.         }
  595.  
  596.         $pagination = new Pagination();
  597.         $pagination->total = $review_total;
  598.         $pagination->page = $page;
  599.         $pagination->limit = 5;
  600.         $pagination->url = $this->url->link('product/product/review', 'product_id=' . $this->request->get['product_id'] . '&page={page}');
  601.  
  602.         $data['pagination'] = $pagination->render();
  603.  
  604.         $data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * 5) + 1 : 0, ((($page - 1) * 5) > ($review_total - 5)) ? $review_total : ((($page - 1) * 5) + 5), $review_total, ceil($review_total / 5));
  605.  
  606.         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) {
  607.             $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/review.tpl', $data));
  608.         } else {
  609.             $this->response->setOutput($this->load->view('default/template/product/review.tpl', $data));
  610.         }
  611.     }
  612.  
  613.     public function write() {
  614.  
  615.         $data = array_merge(isset($data) ? $data : array(), $this->load->language('product/product'));
  616.  
  617.         $json = array();
  618.  
  619.         if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  620.             if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 25)) {
  621.                 $json['error'] = $this->language->get('error_name');
  622.             }
  623.  
  624.             if ((utf8_strlen($this->request->post['text']) < 25) || (utf8_strlen($this->request->post['text']) > 1000)) {
  625.                 $json['error'] = $this->language->get('error_text');
  626.             }
  627.  
  628.             if (empty($this->request->post['rating']) || $this->request->post['rating'] < 0 || $this->request->post['rating'] > 5) {
  629.                 $json['error'] = $this->language->get('error_rating');
  630.             }
  631.  
  632.             // Captcha
  633.             if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
  634.                 $captcha = $this->load->controller('captcha/' . $this->config->get('config_captcha') . '/validate');
  635.  
  636.                 if ($captcha) {
  637.                     $json['error'] = $captcha;
  638.                 }
  639.             }
  640.  
  641.             if (!isset($json['error'])) {
  642.                 $this->load->model('catalog/review');
  643.  
  644.                 $this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post);
  645.  
  646.                 $json['success'] = $this->language->get('text_success');
  647.             }
  648.         }
  649.  
  650.         $this->response->addHeader('Content-Type: application/json');
  651.         $this->response->setOutput(json_encode($json));
  652.     }
  653.  
  654.     public function getRecurringDescription() {
  655.         $this->language->load('product/product');
  656.         $this->load->model('catalog/product');
  657.  
  658.         if (isset($this->request->post['product_id'])) {
  659.             $product_id = $this->request->post['product_id'];
  660.         } else {
  661.             $product_id = 0;
  662.         }
  663.  
  664.         if (isset($this->request->post['recurring_id'])) {
  665.             $recurring_id = $this->request->post['recurring_id'];
  666.         } else {
  667.             $recurring_id = 0;
  668.         }
  669.  
  670.         if (isset($this->request->post['quantity'])) {
  671.             $quantity = $this->request->post['quantity'];
  672.         } else {
  673.             $quantity = 1;
  674.         }
  675.  
  676.         $product_info = $this->model_catalog_product->getProduct($product_id);
  677.         $recurring_info = $this->model_catalog_product->getProfile($product_id, $recurring_id);
  678.  
  679.         $json = array();
  680.  
  681.         if ($product_info && $recurring_info) {
  682.             if (!$json) {
  683.                 $frequencies = array(
  684.                     'day' => $this->language->get('text_day'),
  685.                     'week' => $this->language->get('text_week'),
  686.                     'semi_month' => $this->language->get('text_semi_month'),
  687.                     'month' => $this->language->get('text_month'),
  688.                     'year' => $this->language->get('text_year'),
  689.                 );
  690.  
  691.                 if ($recurring_info['trial_status'] == 1) {
  692.                     $price = $this->currency->format($this->tax->calculate($recurring_info['trial_price'] * $quantity, $product_info['tax_class_id'], $this->config->get('config_tax')));
  693.                     $trial_text = sprintf($this->language->get('text_trial_description'), $price, $recurring_info['trial_cycle'], $frequencies[$recurring_info['trial_frequency']], $recurring_info['trial_duration']) . ' ';
  694.                 } else {
  695.                     $trial_text = '';
  696.                 }
  697.  
  698.                 $price = $this->currency->format($this->tax->calculate($recurring_info['price'] * $quantity, $product_info['tax_class_id'], $this->config->get('config_tax')));
  699.  
  700.                 if ($recurring_info['duration']) {
  701.                     $text = $trial_text . sprintf($this->language->get('text_payment_description'), $price, $recurring_info['cycle'], $frequencies[$recurring_info['frequency']], $recurring_info['duration']);
  702.                 } else {
  703.                     $text = $trial_text . sprintf($this->language->get('text_payment_cancel'), $price, $recurring_info['cycle'], $frequencies[$recurring_info['frequency']], $recurring_info['duration']);
  704.                 }
  705.  
  706.                 $json['success'] = $text;
  707.             }
  708.         }
  709.  
  710.         $this->response->addHeader('Content-Type: application/json');
  711.         $this->response->setOutput(json_encode($json));
  712.     }
  713.  
  714.     public function fastorder() {
  715.  
  716.         $this->load->language('product/product');
  717.  
  718.         $foproductid = $_POST['foproductid'];
  719.         $foproduct = $_POST['foproduct'];
  720.         $name = $_POST['name'];
  721.         $phone = $_POST['phone'];
  722.         $email_address = $_POST['email'];
  723.         $message = $_POST['message'];
  724.  
  725.  
  726.         $email_subject = $this->language->get('email_subject_fast_order');
  727.         $email_body = sprintf($this->language->get('email_body_fast_order'),$foproduct,$name,$email_address,$phone,$message);
  728.  
  729.         $mail = new Mail();
  730.         $mail->protocol = $this->config->get('config_mail_protocol');
  731.         $mail->parameter = $this->config->get('config_mail_parameter');
  732.         $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
  733.         $mail->smtp_username = $this->config->get('config_mail_smtp_username');
  734.         $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
  735.         $mail->smtp_port = $this->config->get('config_mail_smtp_port');
  736.         $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
  737.  
  738. //$mail->setTo($this->config->get('config_email'));
  739.         $mail->setTo($this->config->get('config_mail_alert'));
  740.         $mail->setFrom($this->config->get('config_email'));
  741.         $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
  742.         $mail->setSubject(html_entity_decode($email_subject, ENT_QUOTES, 'UTF-8'));
  743.         $mail->setHtml($this->document->createMail($email_body));
  744. //echo $this->document->createMail($email_body);die;
  745.         $mail->send();
  746.  
  747.         $json = array("success" => true);
  748.         $this->response->addHeader('Content-Type: application/json');
  749.         $this->response->setOutput(json_encode($json));
  750.     }
  751. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement