SHARE
TWEET

controller product.php

a guest Sep 8th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class ControllerCatalogProduct extends Controller {
  3.     private $error = array();
  4.  
  5.     public function index() {
  6.         $this->load->language('catalog/product');
  7.  
  8.         $this->document->setTitle($this->language->get('heading_title'));
  9.  
  10.         $this->load->model('catalog/product');
  11.  
  12.         $this->getList();
  13.     }
  14.  
  15.     public function add() {
  16.         $this->load->language('catalog/product');
  17.  
  18.         $this->document->setTitle($this->language->get('heading_title'));
  19.  
  20.         $this->load->model('catalog/product');
  21.  
  22.         if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  23.             $this->model_catalog_product->addProduct($this->request->post);
  24.  
  25.             $this->session->data['success'] = $this->language->get('text_success');
  26.  
  27.             $url = '';
  28.  
  29.             if (isset($this->request->get['filter_name'])) {
  30.                 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  31.             }
  32.  
  33.             if (isset($this->request->get['filter_model'])) {
  34.                 $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  35.             }
  36.  
  37.             if (isset($this->request->get['filter_price'])) {
  38.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  39.             }
  40.  
  41.             if (isset($this->request->get['filter_quantity'])) {
  42.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  43.             }
  44.  
  45.             if (isset($this->request->get['filter_status'])) {
  46.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  47.             }
  48.  
  49.             if (isset($this->request->get['sort'])) {
  50.                 $url .= '&sort=' . $this->request->get['sort'];
  51.             }
  52.  
  53.             if (isset($this->request->get['order'])) {
  54.                 $url .= '&order=' . $this->request->get['order'];
  55.             }
  56.  
  57.             if (isset($this->request->get['page'])) {
  58.                 $url .= '&page=' . $this->request->get['page'];
  59.             }
  60.  
  61.             $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
  62.         }
  63.  
  64.         $this->getForm();
  65.     }
  66.  
  67.     public function edit() {
  68.         $this->load->language('catalog/product');
  69.  
  70.         $this->document->setTitle($this->language->get('heading_title'));
  71.  
  72.         $this->load->model('catalog/product');
  73.  
  74.         if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  75.             $this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);
  76.  
  77.             $this->session->data['success'] = $this->language->get('text_success');
  78.  
  79.             $url = '';
  80.  
  81.             if (isset($this->request->get['filter_name'])) {
  82.                 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  83.             }
  84.  
  85.             if (isset($this->request->get['filter_model'])) {
  86.                 $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  87.             }
  88.  
  89.             if (isset($this->request->get['filter_price'])) {
  90.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  91.             }
  92.  
  93.             if (isset($this->request->get['filter_quantity'])) {
  94.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  95.             }
  96.  
  97.             if (isset($this->request->get['filter_status'])) {
  98.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  99.             }
  100.  
  101.             if (isset($this->request->get['sort'])) {
  102.                 $url .= '&sort=' . $this->request->get['sort'];
  103.             }
  104.  
  105.             if (isset($this->request->get['order'])) {
  106.                 $url .= '&order=' . $this->request->get['order'];
  107.             }
  108.  
  109.             if (isset($this->request->get['page'])) {
  110.                 $url .= '&page=' . $this->request->get['page'];
  111.             }
  112.  
  113.             $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
  114.         }
  115.  
  116.         $this->getForm();
  117.     }
  118.  
  119.     public function delete() {
  120.         $this->load->language('catalog/product');
  121.  
  122.         $this->document->setTitle($this->language->get('heading_title'));
  123.  
  124.         $this->load->model('catalog/product');
  125.  
  126.         if (isset($this->request->post['selected']) && $this->validateDelete()) {
  127.             foreach ($this->request->post['selected'] as $product_id) {
  128.                 $this->model_catalog_product->deleteProduct($product_id);
  129.             }
  130.  
  131.             $this->session->data['success'] = $this->language->get('text_success');
  132.  
  133.             $url = '';
  134.  
  135.             if (isset($this->request->get['filter_name'])) {
  136.                 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  137.             }
  138.  
  139.             if (isset($this->request->get['filter_model'])) {
  140.                 $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  141.             }
  142.  
  143.             if (isset($this->request->get['filter_price'])) {
  144.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  145.             }
  146.  
  147.             if (isset($this->request->get['filter_quantity'])) {
  148.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  149.             }
  150.  
  151.             if (isset($this->request->get['filter_status'])) {
  152.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  153.             }
  154.  
  155.             if (isset($this->request->get['sort'])) {
  156.                 $url .= '&sort=' . $this->request->get['sort'];
  157.             }
  158.  
  159.             if (isset($this->request->get['order'])) {
  160.                 $url .= '&order=' . $this->request->get['order'];
  161.             }
  162.  
  163.             if (isset($this->request->get['page'])) {
  164.                 $url .= '&page=' . $this->request->get['page'];
  165.             }
  166.  
  167.             $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
  168.         }
  169.  
  170.         $this->getList();
  171.     }
  172.  
  173.     public function copy() {
  174.         $this->load->language('catalog/product');
  175.  
  176.         $this->document->setTitle($this->language->get('heading_title'));
  177.  
  178.         $this->load->model('catalog/product');
  179.  
  180.         if (isset($this->request->post['selected']) && $this->validateCopy()) {
  181.             foreach ($this->request->post['selected'] as $product_id) {
  182.                 $this->model_catalog_product->copyProduct($product_id);
  183.             }
  184.  
  185.             $this->session->data['success'] = $this->language->get('text_success');
  186.  
  187.             $url = '';
  188.  
  189.             if (isset($this->request->get['filter_name'])) {
  190.                 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  191.             }
  192.  
  193.             if (isset($this->request->get['filter_model'])) {
  194.                 $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  195.             }
  196.  
  197.             if (isset($this->request->get['filter_price'])) {
  198.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  199.             }
  200.  
  201.             if (isset($this->request->get['filter_quantity'])) {
  202.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  203.             }
  204.  
  205.             if (isset($this->request->get['filter_status'])) {
  206.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  207.             }
  208.  
  209.             if (isset($this->request->get['sort'])) {
  210.                 $url .= '&sort=' . $this->request->get['sort'];
  211.             }
  212.  
  213.             if (isset($this->request->get['order'])) {
  214.                 $url .= '&order=' . $this->request->get['order'];
  215.             }
  216.  
  217.             if (isset($this->request->get['page'])) {
  218.                 $url .= '&page=' . $this->request->get['page'];
  219.             }
  220.  
  221.             $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
  222.         }
  223.  
  224.         $this->getList();
  225.     }
  226.  
  227.     protected function getList() {
  228.         if (isset($this->request->get['filter_name'])) {
  229.             $filter_name = $this->request->get['filter_name'];
  230.         } else {
  231.             $filter_name = null;
  232.         }
  233.  
  234.         if (isset($this->request->get['filter_model'])) {
  235.             $filter_model = $this->request->get['filter_model'];
  236.         } else {
  237.             $filter_model = null;
  238.         }
  239.  
  240.         if (isset($this->request->get['filter_price'])) {
  241.             $filter_price = $this->request->get['filter_price'];
  242.         } else {
  243.             $filter_price = null;
  244.         }
  245.  
  246.         if (isset($this->request->get['filter_quantity'])) {
  247.             $filter_quantity = $this->request->get['filter_quantity'];
  248.         } else {
  249.             $filter_quantity = null;
  250.         }
  251.  
  252.         if (isset($this->request->get['filter_status'])) {
  253.             $filter_status = $this->request->get['filter_status'];
  254.         } else {
  255.             $filter_status = null;
  256.         }
  257.  
  258.         if (isset($this->request->get['filter_image'])) {
  259.             $filter_image = $this->request->get['filter_image'];
  260.         } else {
  261.             $filter_image = null;
  262.         }
  263.  
  264.         if (isset($this->request->get['sort'])) {
  265.             $sort = $this->request->get['sort'];
  266.         } else {
  267.             $sort = 'pd.name';
  268.         }
  269.  
  270.         if (isset($this->request->get['order'])) {
  271.             $order = $this->request->get['order'];
  272.         } else {
  273.             $order = 'ASC';
  274.         }
  275.  
  276.         if (isset($this->request->get['page'])) {
  277.             $page = $this->request->get['page'];
  278.         } else {
  279.             $page = 1;
  280.         }
  281.  
  282.         $url = '';
  283.  
  284.         if (isset($this->request->get['filter_name'])) {
  285.             $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  286.         }
  287.  
  288.         if (isset($this->request->get['filter_model'])) {
  289.             $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  290.         }
  291.  
  292.         if (isset($this->request->get['filter_price'])) {
  293.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  294.         }
  295.  
  296.         if (isset($this->request->get['filter_quantity'])) {
  297.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  298.         }
  299.  
  300.         if (isset($this->request->get['filter_status'])) {
  301.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  302.         }
  303.  
  304.         if (isset($this->request->get['filter_image'])) {
  305.             $url .= '&filter_image=' . $this->request->get['filter_image'];
  306.         }
  307.  
  308.         if (isset($this->request->get['sort'])) {
  309.             $url .= '&sort=' . $this->request->get['sort'];
  310.         }
  311.  
  312.         if (isset($this->request->get['order'])) {
  313.             $url .= '&order=' . $this->request->get['order'];
  314.         }
  315.  
  316.         if (isset($this->request->get['page'])) {
  317.             $url .= '&page=' . $this->request->get['page'];
  318.         }
  319.  
  320.         $data['breadcrumbs'] = array();
  321.  
  322.         $data['breadcrumbs'][] = array(
  323.             'text' => $this->language->get('text_home'),
  324.             'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
  325.         );
  326.  
  327.         $data['breadcrumbs'][] = array(
  328.             'text' => $this->language->get('heading_title'),
  329.             'href' => $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true)
  330.         );
  331.  
  332.         $data['add'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, true);
  333.         $data['copy'] = $this->url->link('catalog/product/copy', 'token=' . $this->session->data['token'] . $url, true);
  334.         $data['delete'] = $this->url->link('catalog/product/delete', 'token=' . $this->session->data['token'] . $url, true);
  335.  
  336.         $data['products'] = array();
  337.  
  338.         $filter_data = array(
  339.             'filter_name'     => $filter_name,
  340.             'filter_model'    => $filter_model,
  341.             'filter_price'    => $filter_price,
  342.             'filter_quantity' => $filter_quantity,
  343.             'filter_status'   => $filter_status,
  344.             'filter_image'    => $filter_image,
  345.             'sort'            => $sort,
  346.             'order'           => $order,
  347.             'start'           => ($page - 1) * $this->config->get('config_limit_admin'),
  348.             'limit'           => $this->config->get('config_limit_admin')
  349.         );
  350.  
  351.         $this->load->model('tool/image');
  352.  
  353.         $product_total = $this->model_catalog_product->getTotalProducts($filter_data);
  354.  
  355.         $results = $this->model_catalog_product->getProducts($filter_data);
  356.  
  357.         foreach ($results as $result) {
  358.             if (is_file(DIR_IMAGE . $result['image'])) {
  359.                 $image = $this->model_tool_image->resize($result['image'], 40, 40);
  360.             } else {
  361.                 $image = $this->model_tool_image->resize('no_image.png', 40, 40);
  362.             }
  363.  
  364.             $special = false;
  365.  
  366.             $product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']);
  367.  
  368.             foreach ($product_specials  as $product_special) {
  369.                 if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) {
  370.                     $special = $product_special['price'];
  371.  
  372.                     break;
  373.                 }
  374.             }
  375.  
  376.             $data['products'][] = array(
  377.                 'product_id' => $result['product_id'],
  378.                 'image'      => $image,
  379.                 'name'       => $result['name'],
  380.                 'model'      => $result['model'],
  381.                 'price'      => $result['price'],
  382.                 'special'    => $special,
  383.                 'quantity'   => $result['quantity'],
  384.                 'status'     => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
  385.                 'date_modified'       => $result['date_modified'],
  386.                 'edit'       => $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, true)
  387.             );
  388.         }
  389.  
  390.         $data['heading_title'] = $this->language->get('heading_title');
  391.  
  392.         $data['text_list'] = $this->language->get('text_list');
  393.         $data['text_enabled'] = $this->language->get('text_enabled');
  394.         $data['text_disabled'] = $this->language->get('text_disabled');
  395.         $data['text_no_results'] = $this->language->get('text_no_results');
  396.         $data['text_confirm'] = $this->language->get('text_confirm');
  397.  
  398.         $data['column_image'] = $this->language->get('column_image');
  399.         $data['column_name'] = $this->language->get('column_name');
  400.         $data['column_model'] = $this->language->get('column_model');
  401.         $data['column_price'] = $this->language->get('column_price');
  402.         $data['column_quantity'] = $this->language->get('column_quantity');
  403.         $data['column_status'] = $this->language->get('column_status');
  404.         $data['column_action'] = $this->language->get('column_action');
  405.  
  406.         $data['entry_name'] = $this->language->get('entry_name');
  407.         $data['entry_model'] = $this->language->get('entry_model');
  408.         $data['entry_price'] = $this->language->get('entry_price');
  409.         $data['entry_quantity'] = $this->language->get('entry_quantity');
  410.         $data['entry_status'] = $this->language->get('entry_status');
  411.         $data['entry_image'] = $this->language->get('entry_image');
  412.  
  413.         $data['button_copy'] = $this->language->get('button_copy');
  414.         $data['button_add'] = $this->language->get('button_add');
  415.         $data['button_edit'] = $this->language->get('button_edit');
  416.         $data['button_delete'] = $this->language->get('button_delete');
  417.         $data['button_filter'] = $this->language->get('button_filter');
  418.  
  419.         $data['token'] = $this->session->data['token'];
  420.  
  421.         if (isset($this->error['warning'])) {
  422.             $data['error_warning'] = $this->error['warning'];
  423.         } else {
  424.             $data['error_warning'] = '';
  425.         }
  426.  
  427.         if (isset($this->session->data['success'])) {
  428.             $data['success'] = $this->session->data['success'];
  429.  
  430.             unset($this->session->data['success']);
  431.         } else {
  432.             $data['success'] = '';
  433.         }
  434.  
  435.         if (isset($this->request->post['selected'])) {
  436.             $data['selected'] = (array)$this->request->post['selected'];
  437.         } else {
  438.             $data['selected'] = array();
  439.         }
  440.  
  441.         $url = '';
  442.  
  443.         if (isset($this->request->get['filter_name'])) {
  444.             $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  445.         }
  446.  
  447.         if (isset($this->request->get['filter_model'])) {
  448.             $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  449.         }
  450.  
  451.         if (isset($this->request->get['filter_price'])) {
  452.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  453.         }
  454.  
  455.         if (isset($this->request->get['filter_quantity'])) {
  456.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  457.         }
  458.  
  459.         if (isset($this->request->get['filter_status'])) {
  460.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  461.         }
  462.  
  463.         if (isset($this->request->get['filter_image'])) {
  464.             $url .= '&filter_image=' . $this->request->get['filter_image'];
  465.         }
  466.  
  467.         if ($order == 'ASC') {
  468.             $url .= '&order=DESC';
  469.         } else {
  470.             $url .= '&order=ASC';
  471.         }
  472.  
  473.         if (isset($this->request->get['page'])) {
  474.             $url .= '&page=' . $this->request->get['page'];
  475.         }
  476.  
  477.         $data['sort_name'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=pd.name' . $url, true);
  478.         $data['sort_model'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.model' . $url, true);
  479.         $data['sort_price'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.price' . $url, true);
  480.         $data['sort_quantity'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.quantity' . $url, true);
  481.         $data['sort_status'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.status' . $url, true);
  482.         $data['sort_date_modified'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.status' . $url, true);
  483.         $data['sort_order'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.date_modified' . $url, true);
  484.  
  485.         $url = '';
  486.  
  487.         if (isset($this->request->get['filter_name'])) {
  488.             $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  489.         }
  490.  
  491.         if (isset($this->request->get['filter_model'])) {
  492.             $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  493.         }
  494.  
  495.         if (isset($this->request->get['filter_price'])) {
  496.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  497.         }
  498.  
  499.         if (isset($this->request->get['filter_quantity'])) {
  500.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  501.         }
  502.  
  503.         if (isset($this->request->get['filter_status'])) {
  504.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  505.         }
  506.  
  507.         if (isset($this->request->get['filter_image'])) {
  508.             $url .= '&filter_image=' . $this->request->get['filter_image'];
  509.         }
  510.  
  511.         if (isset($this->request->get['sort'])) {
  512.             $url .= '&sort=' . $this->request->get['sort'];
  513.         }
  514.  
  515.         if (isset($this->request->get['order'])) {
  516.             $url .= '&order=' . $this->request->get['order'];
  517.         }
  518.  
  519.         $pagination = new Pagination();
  520.         $pagination->total = $product_total;
  521.         $pagination->page = $page;
  522.         $pagination->limit = $this->config->get('config_limit_admin');
  523.         $pagination->url = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url . '&page={page}', true);
  524.  
  525.         $data['pagination'] = $pagination->render();
  526.  
  527.         $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin')));
  528.  
  529.         $data['filter_name'] = $filter_name;
  530.         $data['filter_model'] = $filter_model;
  531.         $data['filter_price'] = $filter_price;
  532.         $data['filter_quantity'] = $filter_quantity;
  533.         $data['filter_status'] = $filter_status;
  534.         $data['filter_image'] = $filter_image;
  535.  
  536.         $data['sort'] = $sort;
  537.         $data['order'] = $order;
  538.  
  539.         $data['header'] = $this->load->controller('common/header');
  540.         $data['column_left'] = $this->load->controller('common/column_left');
  541.         $data['footer'] = $this->load->controller('common/footer');
  542.  
  543.         $this->response->setOutput($this->load->view('catalog/product_list', $data));
  544.     }
  545.  
  546.     protected function getForm() {
  547.         $data['heading_title'] = $this->language->get('heading_title');
  548.  
  549.         $data['text_form'] = !isset($this->request->get['product_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
  550.         $data['text_enabled'] = $this->language->get('text_enabled');
  551.         $data['text_disabled'] = $this->language->get('text_disabled');
  552.         $data['text_none'] = $this->language->get('text_none');
  553.         $data['text_yes'] = $this->language->get('text_yes');
  554.         $data['text_no'] = $this->language->get('text_no');
  555.         $data['text_plus'] = $this->language->get('text_plus');
  556.         $data['text_minus'] = $this->language->get('text_minus');
  557.         $data['text_default'] = $this->language->get('text_default');
  558.         $data['text_option'] = $this->language->get('text_option');
  559.         $data['text_option_value'] = $this->language->get('text_option_value');
  560.         $data['text_select'] = $this->language->get('text_select');
  561.         $data['text_percent'] = $this->language->get('text_percent');
  562.         $data['text_amount'] = $this->language->get('text_amount');
  563.  
  564.         $data['entry_name'] = $this->language->get('entry_name');
  565.         $data['entry_description'] = $this->language->get('entry_description');
  566.         $data['entry_meta_title'] = $this->language->get('entry_meta_title');
  567.         $data['entry_meta_description'] = $this->language->get('entry_meta_description');
  568.         $data['entry_meta_keyword'] = $this->language->get('entry_meta_keyword');
  569.         $data['entry_keyword'] = $this->language->get('entry_keyword');
  570.         $data['entry_model'] = $this->language->get('entry_model');
  571.         $data['entry_sku'] = $this->language->get('entry_sku');
  572.         $data['entry_upc'] = $this->language->get('entry_upc');
  573.         $data['entry_ean'] = $this->language->get('entry_ean');
  574.         $data['entry_jan'] = $this->language->get('entry_jan');
  575.         $data['entry_isbn'] = $this->language->get('entry_isbn');
  576.         $data['entry_mpn'] = $this->language->get('entry_mpn');
  577.         $data['entry_location'] = $this->language->get('entry_location');
  578.         $data['entry_minimum'] = $this->language->get('entry_minimum');
  579.         $data['entry_shipping'] = $this->language->get('entry_shipping');
  580.         $data['entry_date_available'] = $this->language->get('entry_date_available');
  581.         $data['entry_quantity'] = $this->language->get('entry_quantity');
  582.         $data['entry_stock_status'] = $this->language->get('entry_stock_status');
  583.         $data['entry_price'] = $this->language->get('entry_price');
  584.         $data['entry_tax_class'] = $this->language->get('entry_tax_class');
  585.         $data['entry_points'] = $this->language->get('entry_points');
  586.         $data['entry_option_points'] = $this->language->get('entry_option_points');
  587.         $data['entry_subtract'] = $this->language->get('entry_subtract');
  588.         $data['entry_weight_class'] = $this->language->get('entry_weight_class');
  589.         $data['entry_weight'] = $this->language->get('entry_weight');
  590.         $data['entry_dimension'] = $this->language->get('entry_dimension');
  591.         $data['entry_length_class'] = $this->language->get('entry_length_class');
  592.         $data['entry_length'] = $this->language->get('entry_length');
  593.         $data['entry_width'] = $this->language->get('entry_width');
  594.         $data['entry_height'] = $this->language->get('entry_height');
  595.         $data['entry_image'] = $this->language->get('entry_image');
  596.         $data['entry_additional_image'] = $this->language->get('entry_additional_image');
  597.         $data['entry_store'] = $this->language->get('entry_store');
  598.         $data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
  599.         $data['entry_download'] = $this->language->get('entry_download');
  600.         $data['entry_category'] = $this->language->get('entry_category');
  601.         $data['entry_filter'] = $this->language->get('entry_filter');
  602.         $data['entry_related'] = $this->language->get('entry_related');
  603.         $data['entry_attribute'] = $this->language->get('entry_attribute');
  604.         $data['entry_text'] = $this->language->get('entry_text');
  605.         $data['entry_option'] = $this->language->get('entry_option');
  606.         $data['entry_option_value'] = $this->language->get('entry_option_value');
  607.         $data['entry_required'] = $this->language->get('entry_required');
  608.         $data['entry_sort_order'] = $this->language->get('entry_sort_order');
  609.         $data['entry_status'] = $this->language->get('entry_status');
  610.         $data['entry_date_start'] = $this->language->get('entry_date_start');
  611.         $data['entry_date_end'] = $this->language->get('entry_date_end');
  612.         $data['entry_priority'] = $this->language->get('entry_priority');
  613.         $data['entry_tag'] = $this->language->get('entry_tag');
  614.         $data['entry_customer_group'] = $this->language->get('entry_customer_group');
  615.         $data['entry_reward'] = $this->language->get('entry_reward');
  616.         $data['entry_layout'] = $this->language->get('entry_layout');
  617.         $data['entry_recurring'] = $this->language->get('entry_recurring');
  618.  
  619.         $data['help_keyword'] = $this->language->get('help_keyword');
  620.         $data['help_sku'] = $this->language->get('help_sku');
  621.         $data['help_upc'] = $this->language->get('help_upc');
  622.         $data['help_ean'] = $this->language->get('help_ean');
  623.         $data['help_jan'] = $this->language->get('help_jan');
  624.         $data['help_isbn'] = $this->language->get('help_isbn');
  625.         $data['help_mpn'] = $this->language->get('help_mpn');
  626.         $data['help_minimum'] = $this->language->get('help_minimum');
  627.         $data['help_manufacturer'] = $this->language->get('help_manufacturer');
  628.         $data['help_stock_status'] = $this->language->get('help_stock_status');
  629.         $data['help_points'] = $this->language->get('help_points');
  630.         $data['help_category'] = $this->language->get('help_category');
  631.         $data['help_filter'] = $this->language->get('help_filter');
  632.         $data['help_download'] = $this->language->get('help_download');
  633.         $data['help_related'] = $this->language->get('help_related');
  634.         $data['help_tag'] = $this->language->get('help_tag');
  635.  
  636.         $data['button_save'] = $this->language->get('button_save');
  637.         $data['button_cancel'] = $this->language->get('button_cancel');
  638.         $data['button_attribute_add'] = $this->language->get('button_attribute_add');
  639.         $data['button_option_add'] = $this->language->get('button_option_add');
  640.         $data['button_option_value_add'] = $this->language->get('button_option_value_add');
  641.         $data['button_discount_add'] = $this->language->get('button_discount_add');
  642.         $data['button_special_add'] = $this->language->get('button_special_add');
  643.         $data['button_image_add'] = $this->language->get('button_image_add');
  644.         $data['button_remove'] = $this->language->get('button_remove');
  645.         $data['button_recurring_add'] = $this->language->get('button_recurring_add');
  646.  
  647.         $data['tab_general'] = $this->language->get('tab_general');
  648.         $data['tab_data'] = $this->language->get('tab_data');
  649.         $data['tab_attribute'] = $this->language->get('tab_attribute');
  650.         $data['tab_option'] = $this->language->get('tab_option');
  651.         $data['tab_recurring'] = $this->language->get('tab_recurring');
  652.         $data['tab_discount'] = $this->language->get('tab_discount');
  653.         $data['tab_special'] = $this->language->get('tab_special');
  654.         $data['tab_image'] = $this->language->get('tab_image');
  655.         $data['tab_links'] = $this->language->get('tab_links');
  656.         $data['tab_reward'] = $this->language->get('tab_reward');
  657.         $data['tab_design'] = $this->language->get('tab_design');
  658.         $data['tab_openbay'] = $this->language->get('tab_openbay');
  659.  
  660.         if (isset($this->error['warning'])) {
  661.             $data['error_warning'] = $this->error['warning'];
  662.         } else {
  663.             $data['error_warning'] = '';
  664.         }
  665.  
  666.         if (isset($this->error['name'])) {
  667.             $data['error_name'] = $this->error['name'];
  668.         } else {
  669.             $data['error_name'] = array();
  670.         }
  671.  
  672.         if (isset($this->error['meta_title'])) {
  673.             $data['error_meta_title'] = $this->error['meta_title'];
  674.         } else {
  675.             $data['error_meta_title'] = array();
  676.         }
  677.  
  678.         if (isset($this->error['model'])) {
  679.             $data['error_model'] = $this->error['model'];
  680.         } else {
  681.             $data['error_model'] = '';
  682.         }
  683.  
  684.         if (isset($this->error['keyword'])) {
  685.             $data['error_keyword'] = $this->error['keyword'];
  686.         } else {
  687.             $data['error_keyword'] = '';
  688.         }
  689.  
  690.         $url = '';
  691.  
  692.         if (isset($this->request->get['filter_name'])) {
  693.             $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  694.         }
  695.  
  696.         if (isset($this->request->get['filter_model'])) {
  697.             $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  698.         }
  699.  
  700.         if (isset($this->request->get['filter_price'])) {
  701.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  702.         }
  703.  
  704.         if (isset($this->request->get['filter_quantity'])) {
  705.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  706.         }
  707.  
  708.         if (isset($this->request->get['filter_status'])) {
  709.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  710.         }
  711.  
  712.         if (isset($this->request->get['sort'])) {
  713.             $url .= '&sort=' . $this->request->get['sort'];
  714.         }
  715.  
  716.         if (isset($this->request->get['order'])) {
  717.             $url .= '&order=' . $this->request->get['order'];
  718.         }
  719.  
  720.         if (isset($this->request->get['page'])) {
  721.             $url .= '&page=' . $this->request->get['page'];
  722.         }
  723.  
  724.         $data['breadcrumbs'] = array();
  725.  
  726.         $data['breadcrumbs'][] = array(
  727.             'text' => $this->language->get('text_home'),
  728.             'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
  729.         );
  730.  
  731.         $data['breadcrumbs'][] = array(
  732.             'text' => $this->language->get('heading_title'),
  733.             'href' => $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true)
  734.         );
  735.  
  736.         if (!isset($this->request->get['product_id'])) {
  737.             $data['action'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, true);
  738.         } else {
  739.             $data['action'] = $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'] . $url, true);
  740.         }
  741.  
  742.         $data['cancel'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true);
  743.  
  744.         if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  745.             $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
  746.         }
  747.  
  748.         $data['token'] = $this->session->data['token'];
  749.  
  750.         $this->load->model('localisation/language');
  751.  
  752.         $data['languages'] = $this->model_localisation_language->getLanguages();
  753.  
  754.         if (isset($this->request->post['product_description'])) {
  755.             $data['product_description'] = $this->request->post['product_description'];
  756.         } elseif (isset($this->request->get['product_id'])) {
  757.             $data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
  758.         } else {
  759.             $data['product_description'] = array();
  760.         }
  761.  
  762.         if (isset($this->request->post['model'])) {
  763.             $data['model'] = $this->request->post['model'];
  764.         } elseif (!empty($product_info)) {
  765.             $data['model'] = $product_info['model'];
  766.         } else {
  767.             $data['model'] = '';
  768.         }
  769.  
  770.         if (isset($this->request->post['sku'])) {
  771.             $data['sku'] = $this->request->post['sku'];
  772.         } elseif (!empty($product_info)) {
  773.             $data['sku'] = $product_info['sku'];
  774.         } else {
  775.             $data['sku'] = '';
  776.         }
  777.  
  778.         if (isset($this->request->post['upc'])) {
  779.             $data['upc'] = $this->request->post['upc'];
  780.         } elseif (!empty($product_info)) {
  781.             $data['upc'] = $product_info['upc'];
  782.         } else {
  783.             $data['upc'] = '';
  784.         }
  785.  
  786.         if (isset($this->request->post['ean'])) {
  787.             $data['ean'] = $this->request->post['ean'];
  788.         } elseif (!empty($product_info)) {
  789.             $data['ean'] = $product_info['ean'];
  790.         } else {
  791.             $data['ean'] = '';
  792.         }
  793.  
  794.         if (isset($this->request->post['jan'])) {
  795.             $data['jan'] = $this->request->post['jan'];
  796.         } elseif (!empty($product_info)) {
  797.             $data['jan'] = $product_info['jan'];
  798.         } else {
  799.             $data['jan'] = '';
  800.         }
  801.  
  802.         if (isset($this->request->post['isbn'])) {
  803.             $data['isbn'] = $this->request->post['isbn'];
  804.         } elseif (!empty($product_info)) {
  805.             $data['isbn'] = $product_info['isbn'];
  806.         } else {
  807.             $data['isbn'] = '';
  808.         }
  809.  
  810.         if (isset($this->request->post['mpn'])) {
  811.             $data['mpn'] = $this->request->post['mpn'];
  812.         } elseif (!empty($product_info)) {
  813.             $data['mpn'] = $product_info['mpn'];
  814.         } else {
  815.             $data['mpn'] = '';
  816.         }
  817.  
  818.         if (isset($this->request->post['location'])) {
  819.             $data['location'] = $this->request->post['location'];
  820.         } elseif (!empty($product_info)) {
  821.             $data['location'] = $product_info['location'];
  822.         } else {
  823.             $data['location'] = '';
  824.         }
  825.  
  826.         $this->load->model('setting/store');
  827.  
  828.         $data['stores'] = $this->model_setting_store->getStores();
  829.  
  830.         if (isset($this->request->post['product_store'])) {
  831.             $data['product_store'] = $this->request->post['product_store'];
  832.         } elseif (isset($this->request->get['product_id'])) {
  833.             $data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']);
  834.         } else {
  835.             $data['product_store'] = array(0);
  836.         }
  837.  
  838.         if (isset($this->request->post['keyword'])) {
  839.             $data['keyword'] = $this->request->post['keyword'];
  840.         } elseif (!empty($product_info)) {
  841.             $data['keyword'] = $product_info['keyword'];
  842.         } else {
  843.             $data['keyword'] = '';
  844.         }
  845.  
  846.         if (isset($this->request->post['shipping'])) {
  847.             $data['shipping'] = $this->request->post['shipping'];
  848.         } elseif (!empty($product_info)) {
  849.             $data['shipping'] = $product_info['shipping'];
  850.         } else {
  851.             $data['shipping'] = 1;
  852.         }
  853.  
  854.         if (isset($this->request->post['price'])) {
  855.             $data['price'] = $this->request->post['price'];
  856.         } elseif (!empty($product_info)) {
  857.             $data['price'] = $product_info['price'];
  858.         } else {
  859.             $data['price'] = '';
  860.         }
  861.  
  862.         $this->load->model('catalog/recurring');
  863.  
  864.         $data['recurrings'] = $this->model_catalog_recurring->getRecurrings();
  865.  
  866.         if (isset($this->request->post['product_recurrings'])) {
  867.             $data['product_recurrings'] = $this->request->post['product_recurrings'];
  868.         } elseif (!empty($product_info)) {
  869.             $data['product_recurrings'] = $this->model_catalog_product->getRecurrings($product_info['product_id']);
  870.         } else {
  871.             $data['product_recurrings'] = array();
  872.         }
  873.  
  874.         $this->load->model('localisation/tax_class');
  875.  
  876.         $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
  877.  
  878.         if (isset($this->request->post['tax_class_id'])) {
  879.             $data['tax_class_id'] = $this->request->post['tax_class_id'];
  880.         } elseif (!empty($product_info)) {
  881.             $data['tax_class_id'] = $product_info['tax_class_id'];
  882.         } else {
  883.             $data['tax_class_id'] = 0;
  884.         }
  885.  
  886.         if (isset($this->request->post['date_available'])) {
  887.             $data['date_available'] = $this->request->post['date_available'];
  888.         } elseif (!empty($product_info)) {
  889.             $data['date_available'] = ($product_info['date_available'] != '0000-00-00') ? $product_info['date_available'] : '';
  890.         } else {
  891.             $data['date_available'] = date('Y-m-d');
  892.         }
  893.  
  894.         if (isset($this->request->post['quantity'])) {
  895.             $data['quantity'] = $this->request->post['quantity'];
  896.         } elseif (!empty($product_info)) {
  897.             $data['quantity'] = $product_info['quantity'];
  898.         } else {
  899.             $data['quantity'] = 1;
  900.         }
  901.  
  902.         if (isset($this->request->post['minimum'])) {
  903.             $data['minimum'] = $this->request->post['minimum'];
  904.         } elseif (!empty($product_info)) {
  905.             $data['minimum'] = $product_info['minimum'];
  906.         } else {
  907.             $data['minimum'] = 1;
  908.         }
  909.  
  910.         if (isset($this->request->post['subtract'])) {
  911.             $data['subtract'] = $this->request->post['subtract'];
  912.         } elseif (!empty($product_info)) {
  913.             $data['subtract'] = $product_info['subtract'];
  914.         } else {
  915.             $data['subtract'] = 1;
  916.         }
  917.  
  918.         if (isset($this->request->post['sort_order'])) {
  919.             $data['sort_order'] = $this->request->post['sort_order'];
  920.         } elseif (!empty($product_info)) {
  921.             $data['sort_order'] = $product_info['sort_order'];
  922.         } else {
  923.             $data['sort_order'] = 1;
  924.         }
  925.  
  926.         $this->load->model('localisation/stock_status');
  927.  
  928.         $data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();
  929.  
  930.         if (isset($this->request->post['stock_status_id'])) {
  931.             $data['stock_status_id'] = $this->request->post['stock_status_id'];
  932.         } elseif (!empty($product_info)) {
  933.             $data['stock_status_id'] = $product_info['stock_status_id'];
  934.         } else {
  935.             $data['stock_status_id'] = 0;
  936.         }
  937.  
  938.         if (isset($this->request->post['status'])) {
  939.             $data['status'] = $this->request->post['status'];
  940.         } elseif (!empty($product_info)) {
  941.             $data['status'] = $product_info['status'];
  942.         } else {
  943.             $data['status'] = true;
  944.         }
  945.  
  946.         if (isset($this->request->post['weight'])) {
  947.             $data['weight'] = $this->request->post['weight'];
  948.         } elseif (!empty($product_info)) {
  949.             $data['weight'] = $product_info['weight'];
  950.         } else {
  951.             $data['weight'] = '';
  952.         }
  953.  
  954.         $this->load->model('localisation/weight_class');
  955.  
  956.         $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
  957.  
  958.         if (isset($this->request->post['weight_class_id'])) {
  959.             $data['weight_class_id'] = $this->request->post['weight_class_id'];
  960.         } elseif (!empty($product_info)) {
  961.             $data['weight_class_id'] = $product_info['weight_class_id'];
  962.         } else {
  963.             $data['weight_class_id'] = $this->config->get('config_weight_class_id');
  964.         }
  965.  
  966.         if (isset($this->request->post['length'])) {
  967.             $data['length'] = $this->request->post['length'];
  968.         } elseif (!empty($product_info)) {
  969.             $data['length'] = $product_info['length'];
  970.         } else {
  971.             $data['length'] = '';
  972.         }
  973.  
  974.         if (isset($this->request->post['width'])) {
  975.             $data['width'] = $this->request->post['width'];
  976.         } elseif (!empty($product_info)) {
  977.             $data['width'] = $product_info['width'];
  978.         } else {
  979.             $data['width'] = '';
  980.         }
  981.  
  982.         if (isset($this->request->post['height'])) {
  983.             $data['height'] = $this->request->post['height'];
  984.         } elseif (!empty($product_info)) {
  985.             $data['height'] = $product_info['height'];
  986.         } else {
  987.             $data['height'] = '';
  988.         }
  989.  
  990.         $this->load->model('localisation/length_class');
  991.  
  992.         $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses();
  993.  
  994.         if (isset($this->request->post['length_class_id'])) {
  995.             $data['length_class_id'] = $this->request->post['length_class_id'];
  996.         } elseif (!empty($product_info)) {
  997.             $data['length_class_id'] = $product_info['length_class_id'];
  998.         } else {
  999.             $data['length_class_id'] = $this->config->get('config_length_class_id');
  1000.         }
  1001.  
  1002.         $this->load->model('catalog/manufacturer');
  1003.  
  1004.         if (isset($this->request->post['manufacturer_id'])) {
  1005.             $data['manufacturer_id'] = $this->request->post['manufacturer_id'];
  1006.         } elseif (!empty($product_info)) {
  1007.             $data['manufacturer_id'] = $product_info['manufacturer_id'];
  1008.         } else {
  1009.             $data['manufacturer_id'] = 0;
  1010.         }
  1011.  
  1012.         if (isset($this->request->post['manufacturer'])) {
  1013.             $data['manufacturer'] = $this->request->post['manufacturer'];
  1014.         } elseif (!empty($product_info)) {
  1015.             $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
  1016.  
  1017.             if ($manufacturer_info) {
  1018.                 $data['manufacturer'] = $manufacturer_info['name'];
  1019.             } else {
  1020.                 $data['manufacturer'] = '';
  1021.             }
  1022.         } else {
  1023.             $data['manufacturer'] = '';
  1024.         }
  1025.  
  1026.         // Categories
  1027.         $this->load->model('catalog/category');
  1028.  
  1029.         if (isset($this->request->post['product_category'])) {
  1030.             $categories = $this->request->post['product_category'];
  1031.         } elseif (isset($this->request->get['product_id'])) {
  1032.             $categories = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
  1033.         } else {
  1034.             $categories = array();
  1035.         }
  1036.  
  1037.         $data['product_categories'] = array();
  1038.  
  1039.         foreach ($categories as $category_id) {
  1040.             $category_info = $this->model_catalog_category->getCategory($category_id);
  1041.  
  1042.             if ($category_info) {
  1043.                 $data['product_categories'][] = array(
  1044.                     'category_id' => $category_info['category_id'],
  1045.                     'name'        => ($category_info['path']) ? $category_info['path'] . ' &gt; ' . $category_info['name'] : $category_info['name']
  1046.                 );
  1047.             }
  1048.         }
  1049.  
  1050.         // Filters
  1051.         $this->load->model('catalog/filter');
  1052.  
  1053.         if (isset($this->request->post['product_filter'])) {
  1054.             $filters = $this->request->post['product_filter'];
  1055.         } elseif (isset($this->request->get['product_id'])) {
  1056.             $filters = $this->model_catalog_product->getProductFilters($this->request->get['product_id']);
  1057.         } else {
  1058.             $filters = array();
  1059.         }
  1060.  
  1061.         $data['product_filters'] = array();
  1062.  
  1063.         foreach ($filters as $filter_id) {
  1064.             $filter_info = $this->model_catalog_filter->getFilter($filter_id);
  1065.  
  1066.             if ($filter_info) {
  1067.                 $data['product_filters'][] = array(
  1068.                     'filter_id' => $filter_info['filter_id'],
  1069.                     'name'      => $filter_info['group'] . ' &gt; ' . $filter_info['name']
  1070.                 );
  1071.             }
  1072.         }
  1073.  
  1074.         // Attributes
  1075.         $this->load->model('catalog/attribute');
  1076.  
  1077.         if (isset($this->request->post['product_attribute'])) {
  1078.             $product_attributes = $this->request->post['product_attribute'];
  1079.         } elseif (isset($this->request->get['product_id'])) {
  1080.             $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
  1081.         } else {
  1082.             $product_attributes = array();
  1083.         }
  1084.  
  1085.         $data['product_attributes'] = array();
  1086.  
  1087.         foreach ($product_attributes as $product_attribute) {
  1088.             $attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']);
  1089.  
  1090.             if ($attribute_info) {
  1091.                 $data['product_attributes'][] = array(
  1092.                     'attribute_id'                  => $product_attribute['attribute_id'],
  1093.                     'name'                          => $attribute_info['name'],
  1094.                     'product_attribute_description' => $product_attribute['product_attribute_description']
  1095.                 );
  1096.             }
  1097.         }
  1098.  
  1099.         // Options
  1100.         $this->load->model('catalog/option');
  1101.  
  1102.         if (isset($this->request->post['product_option'])) {
  1103.             $product_options = $this->request->post['product_option'];
  1104.         } elseif (isset($this->request->get['product_id'])) {
  1105.             $product_options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
  1106.         } else {
  1107.             $product_options = array();
  1108.         }
  1109.  
  1110.         $data['product_options'] = array();
  1111.  
  1112.         foreach ($product_options as $product_option) {
  1113.             $product_option_value_data = array();
  1114.  
  1115.             if (isset($product_option['product_option_value'])) {
  1116.                 foreach ($product_option['product_option_value'] as $product_option_value) {
  1117.                     $product_option_value_data[] = array(
  1118.                         'product_option_value_id' => $product_option_value['product_option_value_id'],
  1119.                         'option_value_id'         => $product_option_value['option_value_id'],
  1120.                         'quantity'                => $product_option_value['quantity'],
  1121.                         'subtract'                => $product_option_value['subtract'],
  1122.                         'price'                   => $product_option_value['price'],
  1123.                         'price_prefix'            => $product_option_value['price_prefix'],
  1124.                         'points'                  => $product_option_value['points'],
  1125.                         'points_prefix'           => $product_option_value['points_prefix'],
  1126.                         'weight'                  => $product_option_value['weight'],
  1127.                         'weight_prefix'           => $product_option_value['weight_prefix']
  1128.                     );
  1129.                 }
  1130.             }
  1131.  
  1132.             $data['product_options'][] = array(
  1133.                 'product_option_id'    => $product_option['product_option_id'],
  1134.                 'product_option_value' => $product_option_value_data,
  1135.                 'option_id'            => $product_option['option_id'],
  1136.                 'name'                 => $product_option['name'],
  1137.                 'type'                 => $product_option['type'],
  1138.                 'value'                => isset($product_option['value']) ? $product_option['value'] : '',
  1139.                 'required'             => $product_option['required']
  1140.             );
  1141.         }
  1142.  
  1143.         $data['option_values'] = array();
  1144.  
  1145.         foreach ($data['product_options'] as $product_option) {
  1146.             if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
  1147.                 if (!isset($data['option_values'][$product_option['option_id']])) {
  1148.                     $data['option_values'][$product_option['option_id']] = $this->model_catalog_option->getOptionValues($product_option['option_id']);
  1149.                 }
  1150.             }
  1151.         }
  1152.  
  1153.         $this->load->model('customer/customer_group');
  1154.  
  1155.         $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
  1156.  
  1157.         if (isset($this->request->post['product_discount'])) {
  1158.             $product_discounts = $this->request->post['product_discount'];
  1159.         } elseif (isset($this->request->get['product_id'])) {
  1160.             $product_discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  1161.         } else {
  1162.             $product_discounts = array();
  1163.         }
  1164.  
  1165.         $data['product_discounts'] = array();
  1166.  
  1167.         foreach ($product_discounts as $product_discount) {
  1168.             $data['product_discounts'][] = array(
  1169.                 'customer_group_id' => $product_discount['customer_group_id'],
  1170.                 'quantity'          => $product_discount['quantity'],
  1171.                 'priority'          => $product_discount['priority'],
  1172.                 'price'             => $product_discount['price'],
  1173.                 'date_start'        => ($product_discount['date_start'] != '0000-00-00') ? $product_discount['date_start'] : '',
  1174.                 'date_end'          => ($product_discount['date_end'] != '0000-00-00') ? $product_discount['date_end'] : ''
  1175.             );
  1176.         }
  1177.  
  1178.         if (isset($this->request->post['product_special'])) {
  1179.             $product_specials = $this->request->post['product_special'];
  1180.         } elseif (isset($this->request->get['product_id'])) {
  1181.             $product_specials = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']);
  1182.         } else {
  1183.             $product_specials = array();
  1184.         }
  1185.  
  1186.         $data['product_specials'] = array();
  1187.  
  1188.         foreach ($product_specials as $product_special) {
  1189.             $data['product_specials'][] = array(
  1190.                 'customer_group_id' => $product_special['customer_group_id'],
  1191.                 'priority'          => $product_special['priority'],
  1192.                 'price'             => $product_special['price'],
  1193.                 'date_start'        => ($product_special['date_start'] != '0000-00-00') ? $product_special['date_start'] : '',
  1194.                 'date_end'          => ($product_special['date_end'] != '0000-00-00') ? $product_special['date_end'] :  ''
  1195.             );
  1196.         }
  1197.        
  1198.         // Image
  1199.         if (isset($this->request->post['image'])) {
  1200.             $data['image'] = $this->request->post['image'];
  1201.         } elseif (!empty($product_info)) {
  1202.             $data['image'] = $product_info['image'];
  1203.         } else {
  1204.             $data['image'] = '';
  1205.         }
  1206.  
  1207.         $this->load->model('tool/image');
  1208.  
  1209.         if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {
  1210.             $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);
  1211.         } elseif (!empty($product_info) && is_file(DIR_IMAGE . $product_info['image'])) {
  1212.             $data['thumb'] = $this->model_tool_image->resize($product_info['image'], 100, 100);
  1213.         } else {
  1214.             $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100);
  1215.         }
  1216.  
  1217.         $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
  1218.  
  1219.         // Images
  1220.         if (isset($this->request->post['product_image'])) {
  1221.             $product_images = $this->request->post['product_image'];
  1222.         } elseif (isset($this->request->get['product_id'])) {
  1223.             $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  1224.         } else {
  1225.             $product_images = array();
  1226.         }
  1227.  
  1228.         $data['product_images'] = array();
  1229.  
  1230.         foreach ($product_images as $product_image) {
  1231.             if (is_file(DIR_IMAGE . $product_image['image'])) {
  1232.                 $image = $product_image['image'];
  1233.                 $thumb = $product_image['image'];
  1234.             } else {
  1235.                 $image = '';
  1236.                 $thumb = 'no_image.png';
  1237.             }
  1238.  
  1239.             $data['product_images'][] = array(
  1240.                 'image'      => $image,
  1241.                 'thumb'      => $this->model_tool_image->resize($thumb, 100, 100),
  1242.                 'sort_order' => $product_image['sort_order']
  1243.             );
  1244.         }
  1245.  
  1246.         // Downloads
  1247.         $this->load->model('catalog/download');
  1248.  
  1249.         if (isset($this->request->post['product_download'])) {
  1250.             $product_downloads = $this->request->post['product_download'];
  1251.         } elseif (isset($this->request->get['product_id'])) {
  1252.             $product_downloads = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']);
  1253.         } else {
  1254.             $product_downloads = array();
  1255.         }
  1256.  
  1257.         $data['product_downloads'] = array();
  1258.  
  1259.         foreach ($product_downloads as $download_id) {
  1260.             $download_info = $this->model_catalog_download->getDownload($download_id);
  1261.  
  1262.             if ($download_info) {
  1263.                 $data['product_downloads'][] = array(
  1264.                     'download_id' => $download_info['download_id'],
  1265.                     'name'        => $download_info['name']
  1266.                 );
  1267.             }
  1268.         }
  1269.  
  1270.         if (isset($this->request->post['product_related'])) {
  1271.             $products = $this->request->post['product_related'];
  1272.         } elseif (isset($this->request->get['product_id'])) {
  1273.             $products = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  1274.         } else {
  1275.             $products = array();
  1276.         }
  1277.  
  1278.         $data['product_relateds'] = array();
  1279.  
  1280.         foreach ($products as $product_id) {
  1281.             $related_info = $this->model_catalog_product->getProduct($product_id);
  1282.  
  1283.             if ($related_info) {
  1284.                 $data['product_relateds'][] = array(
  1285.                     'product_id' => $related_info['product_id'],
  1286.                     'name'       => $related_info['name']
  1287.                 );
  1288.             }
  1289.         }
  1290.  
  1291.         if (isset($this->request->post['points'])) {
  1292.             $data['points'] = $this->request->post['points'];
  1293.         } elseif (!empty($product_info)) {
  1294.             $data['points'] = $product_info['points'];
  1295.         } else {
  1296.             $data['points'] = '';
  1297.         }
  1298.  
  1299.         if (isset($this->request->post['product_reward'])) {
  1300.             $data['product_reward'] = $this->request->post['product_reward'];
  1301.         } elseif (isset($this->request->get['product_id'])) {
  1302.             $data['product_reward'] = $this->model_catalog_product->getProductRewards($this->request->get['product_id']);
  1303.         } else {
  1304.             $data['product_reward'] = array();
  1305.         }
  1306.  
  1307.         if (isset($this->request->post['product_layout'])) {
  1308.             $data['product_layout'] = $this->request->post['product_layout'];
  1309.         } elseif (isset($this->request->get['product_id'])) {
  1310.             $data['product_layout'] = $this->model_catalog_product->getProductLayouts($this->request->get['product_id']);
  1311.         } else {
  1312.             $data['product_layout'] = array();
  1313.         }
  1314.  
  1315.         $this->load->model('design/layout');
  1316.  
  1317.         $data['layouts'] = $this->model_design_layout->getLayouts();
  1318.  
  1319.         $data['header'] = $this->load->controller('common/header');
  1320.         $data['column_left'] = $this->load->controller('common/column_left');
  1321.         $data['footer'] = $this->load->controller('common/footer');
  1322.  
  1323.         $this->response->setOutput($this->load->view('catalog/product_form', $data));
  1324.     }
  1325.  
  1326.     protected function validateForm() {
  1327.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1328.             $this->error['warning'] = $this->language->get('error_permission');
  1329.         }
  1330.  
  1331.         foreach ($this->request->post['product_description'] as $language_id => $value) {
  1332.             if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 255)) {
  1333.                 $this->error['name'][$language_id] = $this->language->get('error_name');
  1334.             }
  1335.  
  1336.             if ((utf8_strlen($value['meta_title']) < 3) || (utf8_strlen($value['meta_title']) > 255)) {
  1337.                 $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title');
  1338.             }
  1339.         }
  1340.  
  1341.         if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) {
  1342.             $this->error['model'] = $this->language->get('error_model');
  1343.         }
  1344.  
  1345.         if (utf8_strlen($this->request->post['keyword']) > 0) {
  1346.             $this->load->model('catalog/url_alias');
  1347.  
  1348.             $url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']);
  1349.  
  1350.             if ($url_alias_info && isset($this->request->get['product_id']) && $url_alias_info['query'] != 'product_id=' . $this->request->get['product_id']) {
  1351.                 $this->error['keyword'] = sprintf($this->language->get('error_keyword'));
  1352.             }
  1353.  
  1354.             if ($url_alias_info && !isset($this->request->get['product_id'])) {
  1355.                 $this->error['keyword'] = sprintf($this->language->get('error_keyword'));
  1356.             }
  1357.         }
  1358.  
  1359.         if ($this->error && !isset($this->error['warning'])) {
  1360.             $this->error['warning'] = $this->language->get('error_warning');
  1361.         }
  1362.  
  1363.         return !$this->error;
  1364.     }
  1365.  
  1366.     protected function validateDelete() {
  1367.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1368.             $this->error['warning'] = $this->language->get('error_permission');
  1369.         }
  1370.  
  1371.         return !$this->error;
  1372.     }
  1373.  
  1374.     protected function validateCopy() {
  1375.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1376.             $this->error['warning'] = $this->language->get('error_permission');
  1377.         }
  1378.  
  1379.         return !$this->error;
  1380.     }
  1381.  
  1382.     public function autocomplete() {
  1383.         $json = array();
  1384.  
  1385.         if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_model'])) {
  1386.             $this->load->model('catalog/product');
  1387.             $this->load->model('catalog/option');
  1388.  
  1389.             if (isset($this->request->get['filter_name'])) {
  1390.                 $filter_name = $this->request->get['filter_name'];
  1391.             } else {
  1392.                 $filter_name = '';
  1393.             }
  1394.  
  1395.             if (isset($this->request->get['filter_model'])) {
  1396.                 $filter_model = $this->request->get['filter_model'];
  1397.             } else {
  1398.                 $filter_model = '';
  1399.             }
  1400.  
  1401.             if (isset($this->request->get['limit'])) {
  1402.                 $limit = $this->request->get['limit'];
  1403.             } else {
  1404.                 $limit = 5;
  1405.             }
  1406.  
  1407.             $filter_data = array(
  1408.                 'filter_name'  => $filter_name,
  1409.                 'filter_model' => $filter_model,
  1410.                 'start'        => 0,
  1411.                 'limit'        => $limit
  1412.             );
  1413.  
  1414.             $results = $this->model_catalog_product->getProducts($filter_data);
  1415.  
  1416.             foreach ($results as $result) {
  1417.                 $option_data = array();
  1418.  
  1419.                 $product_options = $this->model_catalog_product->getProductOptions($result['product_id']);
  1420.  
  1421.                 foreach ($product_options as $product_option) {
  1422.                     $option_info = $this->model_catalog_option->getOption($product_option['option_id']);
  1423.  
  1424.                     if ($option_info) {
  1425.                         $product_option_value_data = array();
  1426.  
  1427.                         foreach ($product_option['product_option_value'] as $product_option_value) {
  1428.                             $option_value_info = $this->model_catalog_option->getOptionValue($product_option_value['option_value_id']);
  1429.  
  1430.                             if ($option_value_info) {
  1431.                                 $product_option_value_data[] = array(
  1432.                                     'product_option_value_id' => $product_option_value['product_option_value_id'],
  1433.                                     'option_value_id'         => $product_option_value['option_value_id'],
  1434.                                     'name'                    => $option_value_info['name'],
  1435.                                     'price'                   => (float)$product_option_value['price'] ? $this->currency->format($product_option_value['price'], $this->config->get('config_currency')) : false,
  1436.                                     'price_prefix'            => $product_option_value['price_prefix']
  1437.                                 );
  1438.                             }
  1439.                         }
  1440.  
  1441.                         $option_data[] = array(
  1442.                             'product_option_id'    => $product_option['product_option_id'],
  1443.                             'product_option_value' => $product_option_value_data,
  1444.                             'option_id'            => $product_option['option_id'],
  1445.                             'name'                 => $option_info['name'],
  1446.                             'type'                 => $option_info['type'],
  1447.                             'value'                => $product_option['value'],
  1448.                             'required'             => $product_option['required']
  1449.                         );
  1450.                     }
  1451.                 }
  1452.  
  1453.                 $json[] = array(
  1454.                     'product_id' => $result['product_id'],
  1455.                     'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
  1456.                     'model'      => $result['model'],
  1457.                     'option'     => $option_data,
  1458.                     'price'      => $result['price']
  1459.                 );
  1460.             }
  1461.         }
  1462.  
  1463.         $this->response->addHeader('Content-Type: application/json');
  1464.         $this->response->setOutput(json_encode($json));
  1465.     }
  1466. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top