Advertisement
Guest User

Untitled

a guest
Aug 6th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 45.20 KB | None | 0 0
  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->title = $this->language->get('heading_title');
  9.  
  10.         $this->load->model('catalog/product');
  11.  
  12.         $this->getList();
  13.     }
  14.  
  15.     public function insert() {
  16.         $this->load->language('catalog/product');
  17.  
  18.         $this->document->title = $this->language->get('heading_title');
  19.  
  20.         $this->load->model('catalog/product');
  21.  
  22.         if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  23.            
  24.             $this->model_catalog_product->addProduct($this->request->post);
  25.  
  26.             $this->session->data['success'] = $this->language->get('text_success');
  27.  
  28.             $url = '';
  29.  
  30.             if (isset($this->request->get['filter_name'])) {
  31.                 $url .= '&filter_name=' . $this->request->get['filter_name'];
  32.             }
  33.  
  34.             if (isset($this->request->get['filter_model'])) {
  35.                 $url .= '&filter_model=' . $this->request->get['filter_model'];
  36.             }
  37.  
  38.             if (isset($this->request->get['filter_price'])) {
  39.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  40.             }
  41.            
  42.             if (isset($this->request->get['filter_price_full'])) {
  43.                 $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  44.             }
  45.  
  46.             if (isset($this->request->get['filter_quantity'])) {
  47.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  48.             }
  49.  
  50.             if (isset($this->request->get['filter_status'])) {
  51.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  52.             }
  53.  
  54.             if (isset($this->request->get['page'])) {
  55.                 $url .= '&page=' . $this->request->get['page'];
  56.             }
  57.  
  58.             if (isset($this->request->get['sort'])) {
  59.                 $url .= '&sort=' . $this->request->get['sort'];
  60.             }
  61.  
  62.             if (isset($this->request->get['order'])) {
  63.                 $url .= '&order=' . $this->request->get['order'];
  64.             }
  65.  
  66.             $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  67.         }
  68.  
  69.         $this->getForm();
  70.     }
  71.  
  72.     public function update() {
  73.         $this->load->language('catalog/product');
  74.  
  75.         $this->document->title = $this->language->get('heading_title');
  76.  
  77.         $this->load->model('catalog/product');
  78.        
  79.         if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  80.  
  81.             $this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);
  82.  
  83.             $this->session->data['success'] = $this->language->get('text_success');
  84.  
  85.             $url = '';
  86.  
  87.             if (isset($this->request->get['filter_name'])) {
  88.                 $url .= '&filter_name=' . $this->request->get['filter_name'];
  89.             }
  90.  
  91.             if (isset($this->request->get['filter_model'])) {
  92.                 $url .= '&filter_model=' . $this->request->get['filter_model'];
  93.             }
  94.  
  95.             if (isset($this->request->get['filter_price'])) {
  96.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  97.             }
  98. //Added By Chad        
  99.             if (isset($this->request->get['filter_price_full'])) {
  100.                 $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  101.             }
  102. //Added By Chad
  103.             if (isset($this->request->get['filter_quantity'])) {
  104.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  105.             }
  106.  
  107.             if (isset($this->request->get['filter_status'])) {
  108.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  109.             }
  110.  
  111.             if (isset($this->request->get['page'])) {
  112.                 $url .= '&page=' . $this->request->get['page'];
  113.             }
  114.  
  115.             if (isset($this->request->get['sort'])) {
  116.                 $url .= '&sort=' . $this->request->get['sort'];
  117.             }
  118.  
  119.             if (isset($this->request->get['order'])) {
  120.                 $url .= '&order=' . $this->request->get['order'];
  121.             }
  122.  
  123.             $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  124.         }
  125.  
  126.         $this->getForm();
  127.     }
  128.  
  129.     public function delete() {
  130.         $this->load->language('catalog/product');
  131.  
  132.         $this->document->title = $this->language->get('heading_title');
  133.  
  134.         $this->load->model('catalog/product');
  135.  
  136.         if (isset($this->request->post['selected']) && $this->validateDelete()) {
  137.             foreach ($this->request->post['selected'] as $product_id) {
  138.                 $this->model_catalog_product->deleteProduct($product_id);
  139.             }
  140.  
  141.             $this->session->data['success'] = $this->language->get('text_success');
  142.  
  143.             $url = '';
  144.  
  145.             if (isset($this->request->get['filter_name'])) {
  146.                 $url .= '&filter_name=' . $this->request->get['filter_name'];
  147.             }
  148.  
  149.             if (isset($this->request->get['filter_model'])) {
  150.                 $url .= '&filter_model=' . $this->request->get['filter_model'];
  151.             }
  152.  
  153.             if (isset($this->request->get['filter_price'])) {
  154.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  155.             }
  156. //Added By Chad        
  157.             if (isset($this->request->get['filter_price_full'])) {
  158.                 $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  159.             }
  160. //Added By Chad
  161.             if (isset($this->request->get['filter_quantity'])) {
  162.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  163.             }
  164.  
  165.             if (isset($this->request->get['filter_status'])) {
  166.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  167.             }
  168.  
  169.             if (isset($this->request->get['page'])) {
  170.                 $url .= '&page=' . $this->request->get['page'];
  171.             }
  172.  
  173.             if (isset($this->request->get['sort'])) {
  174.                 $url .= '&sort=' . $this->request->get['sort'];
  175.             }
  176.  
  177.             if (isset($this->request->get['order'])) {
  178.                 $url .= '&order=' . $this->request->get['order'];
  179.             }
  180.  
  181.             $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  182.         }
  183.  
  184.         $this->getList();
  185.     }
  186.  
  187.     public function copy() {
  188.         $this->load->language('catalog/product');
  189.  
  190.         $this->document->title = $this->language->get('heading_title');
  191.  
  192.         $this->load->model('catalog/product');
  193.  
  194.         if (isset($this->request->post['selected']) && $this->validateCopy()) {
  195.             foreach ($this->request->post['selected'] as $product_id) {
  196.                 $this->model_catalog_product->copyProduct($product_id);
  197.             }
  198.  
  199.             $this->session->data['success'] = $this->language->get('text_success');
  200.  
  201.             $url = '';
  202.  
  203.             if (isset($this->request->get['filter_name'])) {
  204.                 $url .= '&filter_name=' . $this->request->get['filter_name'];
  205.             }
  206.  
  207.             if (isset($this->request->get['filter_model'])) {
  208.                 $url .= '&filter_model=' . $this->request->get['filter_model'];
  209.             }
  210.  
  211.             if (isset($this->request->get['filter_price'])) {
  212.                 $url .= '&filter_price=' . $this->request->get['filter_price'];
  213.             }
  214. //Added By Chad        
  215.             if (isset($this->request->get['filter_price_full'])) {
  216.                 $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  217.             }
  218. //Added By Chad
  219.             if (isset($this->request->get['filter_quantity'])) {
  220.                 $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  221.             }
  222.  
  223.             if (isset($this->request->get['filter_status'])) {
  224.                 $url .= '&filter_status=' . $this->request->get['filter_status'];
  225.             }
  226.  
  227.             if (isset($this->request->get['page'])) {
  228.                 $url .= '&page=' . $this->request->get['page'];
  229.             }
  230.  
  231.             if (isset($this->request->get['sort'])) {
  232.                 $url .= '&sort=' . $this->request->get['sort'];
  233.             }
  234.  
  235.             if (isset($this->request->get['order'])) {
  236.                 $url .= '&order=' . $this->request->get['order'];
  237.             }
  238.  
  239.             $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  240.         }
  241.  
  242.         $this->getList();
  243.     }
  244.  
  245.     private function getList() {
  246.         if (isset($this->request->get['page'])) {
  247.             $page = $this->request->get['page'];
  248.         } else {
  249.             $page = 1;
  250.         }
  251.  
  252.         if (isset($this->request->get['sort'])) {
  253.             $sort = $this->request->get['sort'];
  254.         } else {
  255.             $sort = 'pd.name';
  256.         }
  257.  
  258.         if (isset($this->request->get['order'])) {
  259.             $order = $this->request->get['order'];
  260.         } else {
  261.             $order = 'ASC';
  262.         }
  263.  
  264.         if (isset($this->request->get['filter_name'])) {
  265.             $filter_name = $this->request->get['filter_name'];
  266.         } else {
  267.             $filter_name = NULL;
  268.         }
  269.  
  270.         if (isset($this->request->get['filter_model'])) {
  271.             $filter_model = $this->request->get['filter_model'];
  272.         } else {
  273.             $filter_model = NULL;
  274.         }
  275.  
  276.         if (isset($this->request->get['filter_price'])) {
  277.             $filter_price = $this->request->get['filter_price'];
  278.         } else {
  279.             $filter_price = NULL;
  280.         }
  281. //Added By Chad    
  282.         if (isset($this->request->get['filter_price_full'])) {
  283.             $filter_price_full = $this->request->get['filter_price_full'];
  284.         } else {
  285.             $filter_price_full = NULL;
  286.         }
  287. //Added By Chad
  288.         if (isset($this->request->get['filter_quantity'])) {
  289.             $filter_quantity = $this->request->get['filter_quantity'];
  290.         } else {
  291.             $filter_quantity = NULL;
  292.         }
  293.  
  294.         if (isset($this->request->get['filter_status'])) {
  295.             $filter_status = $this->request->get['filter_status'];
  296.         } else {
  297.             $filter_status = NULL;
  298.         }
  299.  
  300.         $url = '';
  301.  
  302.         if (isset($this->request->get['filter_name'])) {
  303.             $url .= '&filter_name=' . $this->request->get['filter_name'];
  304.         }
  305.  
  306.         if (isset($this->request->get['filter_model'])) {
  307.             $url .= '&filter_model=' . $this->request->get['filter_model'];
  308.         }
  309.  
  310.         if (isset($this->request->get['filter_price'])) {
  311.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  312.         }
  313. //Added By Chad
  314.         if (isset($this->request->get['filter_price_full'])) {
  315.             $url .= '&filter_price_full' . $this->request->get['filter_price_full'];
  316.         }
  317. //Added By Chad
  318.         if (isset($this->request->get['filter_quantity'])) {
  319.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  320.         }
  321.  
  322.         if (isset($this->request->get['filter_status'])) {
  323.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  324.         }
  325.  
  326.         if (isset($this->request->get['page'])) {
  327.             $url .= '&page=' . $this->request->get['page'];
  328.         }
  329.  
  330.         if (isset($this->request->get['sort'])) {
  331.             $url .= '&sort=' . $this->request->get['sort'];
  332.         }
  333.  
  334.         if (isset($this->request->get['order'])) {
  335.             $url .= '&order=' . $this->request->get['order'];
  336.         }
  337.  
  338.         $this->document->breadcrumbs = array();
  339.  
  340.         $this->document->breadcrumbs[] = array(
  341.             'href'      => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
  342.             'text'      => $this->language->get('text_home'),
  343.             'separator' => FALSE
  344.         );
  345.  
  346.         $this->document->breadcrumbs[] = array(
  347.             'href'      => HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url,
  348.             'text'      => $this->language->get('heading_title'),
  349.             'separator' => ' :: '
  350.         );
  351.  
  352.         $this->data['insert'] = HTTPS_SERVER . 'index.php?route=catalog/product/insert&token=' . $this->session->data['token'] . $url;
  353.         $this->data['copy'] = HTTPS_SERVER . 'index.php?route=catalog/product/copy&token=' . $this->session->data['token'] . $url;
  354.         $this->data['delete'] = HTTPS_SERVER . 'index.php?route=catalog/product/delete&token=' . $this->session->data['token'] . $url;
  355.  
  356.         $this->data['products'] = array();
  357.  
  358.         $data = array(
  359.             'filter_name'     => $filter_name,
  360.             'filter_model'    => $filter_model,
  361.             'filter_price'    => $filter_price,
  362.             'filter_price_full'   => $filter_price_full,//Added By Chad
  363.             'filter_quantity' => $filter_quantity,
  364.             'filter_status'   => $filter_status,
  365.             'sort'            => $sort,
  366.             'order'           => $order,
  367.             'start'           => ($page - 1) * $this->config->get('config_admin_limit'),
  368.             'limit'           => $this->config->get('config_admin_limit')
  369.         );
  370.  
  371.         $this->load->model('tool/image');
  372.  
  373.         $product_total = $this->model_catalog_product->getTotalProducts($data);
  374.  
  375.         $results = $this->model_catalog_product->getProducts($data);
  376.  
  377.         foreach ($results as $result) {
  378.             $action = array();
  379.  
  380.             $action[] = array(
  381.                 'text' => $this->language->get('text_edit'),
  382.                 'href' => HTTPS_SERVER . 'index.php?route=catalog/product/update&token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url
  383.             );
  384.  
  385.             if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
  386.                 $image = $this->model_tool_image->resize($result['image'], 40, 40);
  387.             } else {
  388.                 $image = $this->model_tool_image->resize('no_image.jpg', 40, 40);
  389.             }
  390.  
  391.             $product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']);
  392.  
  393.              if ($product_specials) {
  394.                 $special = reset($product_specials);
  395.                 if($special['date_start'] > date('Y-m-d') || $special['date_end'] < date('Y-m-d')) {
  396.                     $special = FALSE;
  397.                 }
  398.             } else {
  399.                 $special = FALSE;
  400.             }
  401.  
  402.             $this->data['products'][] = array(
  403.                 'product_id' => $result['product_id'],
  404.                 'name'       => $result['name'],
  405.                 'model'      => $result['model'],
  406.                 'price'      => $result['price'],
  407.                 'price_full' => $result['price_full'],//Added By Chad
  408.                 'special'    => $special['price'],
  409.                 'image'      => $image,
  410.                 'quantity'   => $result['quantity'],
  411.                 'status'     => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
  412.                 'selected'   => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']),
  413.                 'action'     => $action
  414.             );
  415.         }
  416.  
  417.         $this->data['heading_title'] = $this->language->get('heading_title');
  418.  
  419.         $this->data['text_enabled'] = $this->language->get('text_enabled');
  420.         $this->data['text_disabled'] = $this->language->get('text_disabled');
  421.         $this->data['text_no_results'] = $this->language->get('text_no_results');
  422.         $this->data['text_image_manager'] = $this->language->get('text_image_manager');
  423.  
  424.         $this->data['column_image'] = $this->language->get('column_image');
  425.         $this->data['column_name'] = $this->language->get('column_name');
  426.         $this->data['column_model'] = $this->language->get('column_model');
  427.         $this->data['column_price'] = $this->language->get('column_price');
  428.         $this->data['column_price_full'] = $this->language->get('column_price_full');//Added By Chad
  429.         $this->data['column_quantity'] = $this->language->get('column_quantity');
  430.         $this->data['column_status'] = $this->language->get('column_status');
  431.         $this->data['column_action'] = $this->language->get('column_action');
  432.  
  433.         $this->data['button_copy'] = $this->language->get('button_copy');
  434.         $this->data['button_insert'] = $this->language->get('button_insert');
  435.         $this->data['button_delete'] = $this->language->get('button_delete');
  436.         $this->data['button_filter'] = $this->language->get('button_filter');
  437.  
  438.         $this->data['token'] = $this->session->data['token'];
  439.  
  440.         if (isset($this->error['warning'])) {
  441.             $this->data['error_warning'] = $this->error['warning'];
  442.         } else {
  443.             $this->data['error_warning'] = '';
  444.         }
  445.  
  446.         if (isset($this->session->data['success'])) {
  447.             $this->data['success'] = $this->session->data['success'];
  448.  
  449.             unset($this->session->data['success']);
  450.         } else {
  451.             $this->data['success'] = '';
  452.         }
  453.  
  454.         $url = '';
  455.  
  456.         if (isset($this->request->get['filter_name'])) {
  457.             $url .= '&filter_name=' . $this->request->get['filter_name'];
  458.         }
  459.  
  460.         if (isset($this->request->get['filter_model'])) {
  461.             $url .= '&filter_model=' . $this->request->get['filter_model'];
  462.         }
  463.  
  464.         if (isset($this->request->get['filter_price'])) {
  465.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  466.         }
  467. //Added By Chad    
  468.         if (isset($this->request->get['filter_price_full'])) {
  469.             $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  470.         }
  471. //Added By Chad
  472.         if (isset($this->request->get['filter_quantity'])) {
  473.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  474.         }
  475.  
  476.         if (isset($this->request->get['filter_status'])) {
  477.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  478.         }
  479.  
  480.         if ($order == 'ASC') {
  481.             $url .= '&order=DESC';
  482.         } else {
  483.             $url .= '&order=ASC';
  484.         }
  485.  
  486.         if (isset($this->request->get['page'])) {
  487.             $url .= '&page=' . $this->request->get['page'];
  488.         }
  489.  
  490.         $this->data['sort_name'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=pd.name' . $url;
  491.         $this->data['sort_model'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.model' . $url;
  492.         $this->data['sort_price'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.price' . $url;
  493.         $this->data['sort_quantity'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.quantity' . $url;
  494.         $this->data['sort_status'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.status' . $url;
  495.         $this->data['sort_order'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.sort_order' . $url;
  496.  
  497.         $url = '';
  498.  
  499.         if (isset($this->request->get['filter_name'])) {
  500.             $url .= '&filter_name=' . $this->request->get['filter_name'];
  501.         }
  502.  
  503.         if (isset($this->request->get['filter_model'])) {
  504.             $url .= '&filter_model=' . $this->request->get['filter_model'];
  505.         }
  506.  
  507.         if (isset($this->request->get['filter_price'])) {
  508.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  509.         }
  510.        
  511.         if (isset($this->request->get['filter_price_full'])) {
  512.             $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  513.         }
  514.  
  515.         if (isset($this->request->get['filter_quantity'])) {
  516.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  517.         }
  518.  
  519.         if (isset($this->request->get['filter_status'])) {
  520.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  521.         }
  522.  
  523.         if (isset($this->request->get['sort'])) {
  524.             $url .= '&sort=' . $this->request->get['sort'];
  525.         }
  526.  
  527.         if (isset($this->request->get['order'])) {
  528.             $url .= '&order=' . $this->request->get['order'];
  529.         }
  530.  
  531.         $pagination = new Pagination();
  532.         $pagination->total = $product_total;
  533.         $pagination->page = $page;
  534.         $pagination->limit = $this->config->get('config_admin_limit');
  535.         $pagination->text = $this->language->get('text_pagination');
  536.         $pagination->url = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url . '&page={page}';
  537.  
  538.         $this->data['pagination'] = $pagination->render();
  539.  
  540.         $this->data['filter_name'] = $filter_name;
  541.         $this->data['filter_model'] = $filter_model;
  542.         $this->data['filter_price'] = $filter_price;
  543.         $this->data['filter_price_full'] = $filter_price_full;
  544.         $this->data['filter_quantity'] = $filter_quantity;
  545.         $this->data['filter_status'] = $filter_status;
  546.  
  547.         $this->data['sort'] = $sort;
  548.         $this->data['order'] = $order;
  549.  
  550.         $this->template = 'catalog/product_list.tpl';
  551.         $this->children = array(
  552.             'common/header',
  553.             'common/footer'
  554.         );
  555.  
  556.         $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  557.     }
  558.  
  559.     private function getForm() {
  560.         $this->data['heading_title'] = $this->language->get('heading_title');
  561.  
  562.         $this->data['text_enabled'] = $this->language->get('text_enabled');
  563.         $this->data['text_disabled'] = $this->language->get('text_disabled');
  564.         $this->data['text_none'] = $this->language->get('text_none');
  565.         $this->data['text_yes'] = $this->language->get('text_yes');
  566.         $this->data['text_no'] = $this->language->get('text_no');
  567.         $this->data['text_plus'] = $this->language->get('text_plus');
  568.         $this->data['text_minus'] = $this->language->get('text_minus');
  569.         $this->data['text_default'] = $this->language->get('text_default');
  570.         $this->data['text_image_manager'] = $this->language->get('text_image_manager');
  571.         $this->data['text_option'] = $this->language->get('text_option');
  572.         $this->data['text_option_value'] = $this->language->get('text_option_value');
  573.         $this->data['text_select'] = $this->language->get('text_select');
  574.         $this->data['text_none'] = $this->language->get('text_none');
  575.  
  576.         $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  577.         $this->data['tab_links'] = $this->language->get('tab_links');
  578.  
  579.         $this->data['entry_name'] = $this->language->get('entry_name');
  580.         $this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
  581.         $this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
  582.         $this->data['entry_description'] = $this->language->get('entry_description');
  583.         $this->data['entry_store'] = $this->language->get('entry_store');
  584.         $this->data['entry_keyword'] = $this->language->get('entry_keyword');
  585.         $this->data['entry_model'] = $this->language->get('entry_model');
  586.         $this->data['entry_sku'] = $this->language->get('entry_sku');
  587.         $this->data['entry_location'] = $this->language->get('entry_location');
  588.         $this->data['entry_minimum'] = $this->language->get('entry_minimum');
  589.         $this->data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
  590.         $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  591.         $this->data['entry_date_available'] = $this->language->get('entry_date_available');
  592.         $this->data['entry_quantity'] = $this->language->get('entry_quantity');
  593.         $this->data['entry_stock_status'] = $this->language->get('entry_stock_status');
  594.         $this->data['entry_status'] = $this->language->get('entry_status');
  595.         $this->data['entry_tax_class'] = $this->language->get('entry_tax_class');
  596.         $this->data['entry_price'] = $this->language->get('entry_price');
  597.         $this->data['entry_price_full'] = $this->language->get('entry_price_full');
  598.         $this->data['entry_cost'] = $this->language->get('entry_cost');
  599.         $this->data['entry_subtract'] = $this->language->get('entry_subtract');
  600.         $this->data['entry_weight_class'] = $this->language->get('entry_weight_class');
  601.         $this->data['entry_weight'] = $this->language->get('entry_weight');
  602.         $this->data['entry_dimension'] = $this->language->get('entry_dimension');
  603.         $this->data['entry_length'] = $this->language->get('entry_length');
  604.         $this->data['entry_image'] = $this->language->get('entry_image');
  605.         $this->data['entry_attribute'] = $this->language->get('entry_attribute');
  606.         $this->data['entry_download'] = $this->language->get('entry_download');
  607.         $this->data['entry_category'] = $this->language->get('entry_category');
  608.         $this->data['entry_related'] = $this->language->get('entry_related');
  609.         $this->data['entry_option'] = $this->language->get('entry_option');
  610.         $this->data['entry_option_value'] = $this->language->get('entry_option_value');
  611.         $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
  612.         $this->data['entry_prefix'] = $this->language->get('entry_prefix');
  613.         $this->data['entry_reqd'] = $this->language->get('entry_reqd');
  614.         $this->data['entry_listoptions'] = $this->language->get('entry_listoptions');
  615.         $this->data['entry_optionmaxlength'] = $this->language->get('entry_optionmaxlength');
  616.  
  617.         $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  618.         $this->data['entry_date_start'] = $this->language->get('entry_date_start');
  619.         $this->data['entry_date_end'] = $this->language->get('entry_date_end');
  620.         $this->data['entry_priority'] = $this->language->get('entry_priority');
  621.         $this->data['entry_tags'] = $this->language->get('entry_tags');
  622.  
  623.         $this->data['button_save'] = $this->language->get('button_save');
  624.         $this->data['button_cancel'] = $this->language->get('button_cancel');
  625.         $this->data['button_add_option'] = $this->language->get('button_add_option');
  626.         $this->data['button_add_option_value'] = $this->language->get('button_add_option_value');
  627.         $this->data['button_add_txtoption'] = $this->language->get('button_add_txtoption');
  628.         $this->data['button_add_discount'] = $this->language->get('button_add_discount');
  629.         $this->data['button_add_special'] = $this->language->get('button_add_special');
  630.         $this->data['button_add_image'] = $this->language->get('button_add_image');
  631.         $this->data['button_remove'] = $this->language->get('button_remove');
  632.  
  633.         $this->data['tab_general'] = $this->language->get('tab_general');
  634.         $this->data['tab_data'] = $this->language->get('tab_data');
  635.         $this->data['tab_discount'] = $this->language->get('tab_discount');
  636.         $this->data['tab_special'] = $this->language->get('tab_special');
  637.         $this->data['tab_option'] = $this->language->get('tab_option');
  638.         $this->data['tab_image'] = $this->language->get('tab_image');
  639.  
  640.         if (isset($this->error['warning'])) {
  641.             $this->data['error_warning'] = $this->error['warning'];
  642.         } else {
  643.             $this->data['error_warning'] = '';
  644.         }
  645.  
  646.         if (isset($this->error['name'])) {
  647.             $this->data['error_name'] = $this->error['name'];
  648.         } else {
  649.             $this->data['error_name'] = '';
  650.         }
  651.  
  652.         if (isset($this->error['meta_description'])) {
  653.             $this->data['error_meta_description'] = $this->error['meta_description'];
  654.         } else {
  655.             $this->data['error_meta_description'] = '';
  656.         }
  657.  
  658.         if (isset($this->error['description'])) {
  659.             $this->data['error_description'] = $this->error['description'];
  660.         } else {
  661.             $this->data['error_description'] = '';
  662.         }
  663.  
  664.         if (isset($this->error['model'])) {
  665.             $this->data['error_model'] = $this->error['model'];
  666.         } else {
  667.             $this->data['error_model'] = '';
  668.         }
  669.  
  670.         if (isset($this->error['date_available'])) {
  671.             $this->data['error_date_available'] = $this->error['date_available'];
  672.         } else {
  673.             $this->data['error_date_available'] = '';
  674.         }
  675.  
  676.         $url = '';
  677.  
  678.         if (isset($this->request->get['filter_name'])) {
  679.             $url .= '&filter_name=' . $this->request->get['filter_name'];
  680.         }
  681.  
  682.         if (isset($this->request->get['filter_model'])) {
  683.             $url .= '&filter_model=' . $this->request->get['filter_model'];
  684.         }
  685.  
  686.         if (isset($this->request->get['filter_price'])) {
  687.             $url .= '&filter_price=' . $this->request->get['filter_price'];
  688.         }
  689.        
  690.         if (isset($this->request->get['filter_price_full'])) {
  691.             $url .= '&filter_price_full=' . $this->request->get['filter_price_full'];
  692.         }
  693.  
  694.         if (isset($this->request->get['filter_quantity'])) {
  695.             $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  696.         }
  697.  
  698.         if (isset($this->request->get['filter_status'])) {
  699.             $url .= '&filter_status=' . $this->request->get['filter_status'];
  700.         }
  701.  
  702.         if (isset($this->request->get['page'])) {
  703.             $url .= '&page=' . $this->request->get['page'];
  704.         }
  705.  
  706.         if (isset($this->request->get['sort'])) {
  707.             $url .= '&sort=' . $this->request->get['sort'];
  708.         }
  709.  
  710.         if (isset($this->request->get['order'])) {
  711.             $url .= '&order=' . $this->request->get['order'];
  712.         }
  713.  
  714.         $this->document->breadcrumbs = array();
  715.  
  716.         $this->document->breadcrumbs[] = array(
  717.             'href'      => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
  718.             'text'      => $this->language->get('text_home'),
  719.             'separator' => FALSE
  720.         );
  721.  
  722.         $this->document->breadcrumbs[] = array(
  723.             'href'      => HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url,
  724.             'text'      => $this->language->get('heading_title'),
  725.             'separator' => ' :: '
  726.         );
  727.  
  728.         if (!isset($this->request->get['product_id'])) {
  729.             $this->data['action'] = HTTPS_SERVER . 'index.php?route=catalog/product/insert&token=' . $this->session->data['token'] . $url;
  730.         } else {
  731.             $this->data['action'] = HTTPS_SERVER . 'index.php?route=catalog/product/update&token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'] . $url;
  732.         }
  733.  
  734.         $this->data['cancel'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url;
  735.  
  736.         $this->data['token'] = $this->session->data['token'];
  737.  
  738.         if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  739.             $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
  740.         }
  741.  
  742.         $this->load->model('localisation/language');
  743.  
  744.         $this->data['languages'] = $this->model_localisation_language->getLanguages();
  745.  
  746.         if (isset($this->request->post['product_description'])) {
  747.             $this->data['product_description'] = $this->request->post['product_description'];
  748.         } elseif (isset($product_info)) {
  749.             $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
  750.         } else {
  751.             $this->data['product_description'] = array();
  752.         }
  753.  
  754.         if (isset($this->request->post['model'])) {
  755.             $this->data['model'] = $this->request->post['model'];
  756.         } elseif (isset($product_info)) {
  757.             $this->data['model'] = $product_info['model'];
  758.         } else {
  759.             $this->data['model'] = '';
  760.         }
  761.  
  762.         if (isset($this->request->post['sku'])) {
  763.             $this->data['sku'] = $this->request->post['sku'];
  764.         } elseif (isset($product_info)) {
  765.             $this->data['sku'] = $product_info['sku'];
  766.         } else {
  767.             $this->data['sku'] = '';
  768.         }
  769.  
  770.         if (isset($this->request->post['location'])) {
  771.             $this->data['location'] = $this->request->post['location'];
  772.         } elseif (isset($product_info)) {
  773.             $this->data['location'] = $product_info['location'];
  774.         } else {
  775.             $this->data['location'] = '';
  776.         }
  777.  
  778.         $this->load->model('setting/store');
  779.  
  780.         $this->data['stores'] = $this->model_setting_store->getStores();
  781.  
  782.         if (isset($this->request->post['product_store'])) {
  783.             $this->data['product_store'] = $this->request->post['product_store'];
  784.         } elseif (isset($product_info)) {
  785.             $this->data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']);
  786.         } else {
  787.             $this->data['product_store'] = array(0);
  788.         }
  789.  
  790.         if (isset($this->request->post['keyword'])) {
  791.             $this->data['keyword'] = $this->request->post['keyword'];
  792.         } elseif (isset($product_info)) {
  793.             $this->data['keyword'] = $product_info['keyword'];
  794.         } else {
  795.             $this->data['keyword'] = '';
  796.         }
  797.  
  798.         if (isset($this->request->post['product_tags'])) {
  799.             $this->data['product_tags'] = $this->request->post['product_tags'];
  800.         } elseif (isset($product_info)) {
  801.             $this->data['product_tags'] = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
  802.         } else {
  803.             $this->data['product_tags'] = array();
  804.         }
  805.  
  806.         if (isset($this->request->post['image'])) {
  807.             $this->data['image'] = $this->request->post['image'];
  808.         } elseif (isset($product_info)) {
  809.             $this->data['image'] = $product_info['image'];
  810.         } else {
  811.             $this->data['image'] = '';
  812.         }
  813.  
  814.         $this->load->model('tool/image');
  815.  
  816.         if (isset($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
  817.             $this->data['preview'] = $this->model_tool_image->resize($product_info['image'], 100, 100);
  818.         } else {
  819.             $this->data['preview'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
  820.         }
  821.  
  822.         $this->load->model('catalog/manufacturer');
  823.  
  824.         $this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers();
  825.  
  826.         if (isset($this->request->post['manufacturer_id'])) {
  827.             $this->data['manufacturer_id'] = $this->request->post['manufacturer_id'];
  828.         } elseif (isset($product_info)) {
  829.             $this->data['manufacturer_id'] = $product_info['manufacturer_id'];
  830.         } else {
  831.             $this->data['manufacturer_id'] = 0;
  832.         }
  833.  
  834.         if (isset($this->request->post['shipping'])) {
  835.             $this->data['shipping'] = $this->request->post['shipping'];
  836.         } elseif (isset($product_info)) {
  837.             $this->data['shipping'] = $product_info['shipping'];
  838.         } else {
  839.             $this->data['shipping'] = 1;
  840.         }
  841.  
  842.         if (isset($this->request->post['date_available'])) {
  843.             $this->data['date_available'] = $this->request->post['date_available'];
  844.         } elseif (isset($product_info)) {
  845.             $this->data['date_available'] = date('Y-m-d', strtotime($product_info['date_available']));
  846.         } else {
  847.             $this->data['date_available'] = date('Y-m-d', time()-86400);
  848.         }
  849.  
  850.         if (isset($this->request->post['quantity'])) {
  851.             $this->data['quantity'] = $this->request->post['quantity'];
  852.         } elseif (isset($product_info)) {
  853.             $this->data['quantity'] = $product_info['quantity'];
  854.         } else {
  855.             $this->data['quantity'] = 1;
  856.         }
  857.  
  858.         if (isset($this->request->post['minimum'])) {
  859.             $this->data['minimum'] = $this->request->post['minimum'];
  860.         } elseif (isset($product_info)) {
  861.             $this->data['minimum'] = $product_info['minimum'];
  862.         } else {
  863.             $this->data['minimum'] = 1;
  864.         }
  865.  
  866.         if (isset($this->request->post['subtract'])) {
  867.             $this->data['subtract'] = $this->request->post['subtract'];
  868.         } elseif (isset($product_info)) {
  869.             $this->data['subtract'] = $product_info['subtract'];
  870.         } else {
  871.             $this->data['subtract'] = 1;
  872.         }
  873.  
  874.         if (isset($this->request->post['sort_order'])) {
  875.             $this->data['sort_order'] = $this->request->post['sort_order'];
  876.         } elseif (isset($product_info)) {
  877.             $this->data['sort_order'] = $product_info['sort_order'];
  878.         } else {
  879.             $this->data['sort_order'] = 1;
  880.         }
  881.  
  882.         $this->load->model('localisation/stock_status');
  883.  
  884.         $this->data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();
  885.  
  886.         if (isset($this->request->post['stock_status_id'])) {
  887.             $this->data['stock_status_id'] = $this->request->post['stock_status_id'];
  888.         } else if (isset($product_info)) {
  889.             $this->data['stock_status_id'] = $product_info['stock_status_id'];
  890.         } else {
  891.             $this->data['stock_status_id'] = $this->config->get('config_stock_status_id');
  892.         }
  893.  
  894.         if (isset($this->request->post['price'])) {
  895.             $this->data['price'] = $this->request->post['price'];
  896.         } else if (isset($product_info)) {
  897.             $this->data['price'] = $product_info['price'];
  898.         } else {
  899.             $this->data['price'] = '';
  900.         }
  901.         if (isset($this->request->post['price_full'])) {
  902.             $this->data['price_full'] = $this->request->post['price_full'];
  903.         } else if (isset($product_info)) {
  904.             $this->data['price_full'] = $product_info['price_full'];
  905.         } else {
  906.             $this->data['price_full'] = '';
  907.         }
  908.  
  909.         if (isset($this->request->post['cost'])) {
  910.             $this->data['cost'] = $this->request->post['cost'];
  911.         } else if (isset($product_info)) {
  912.             $this->data['cost'] = $product_info['cost'];
  913.         } else {
  914.             $this->data['cost'] = '';
  915.         }
  916.  
  917.         if (isset($this->request->post['status'])) {
  918.             $this->data['status'] = $this->request->post['status'];
  919.         } else if (isset($product_info)) {
  920.             $this->data['status'] = $product_info['status'];
  921.         } else {
  922.             $this->data['status'] = 1;
  923.         }
  924.  
  925.         $this->load->model('localisation/tax_class');
  926.  
  927.         $this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
  928.  
  929.         if (isset($this->request->post['tax_class_id'])) {
  930.             $this->data['tax_class_id'] = $this->request->post['tax_class_id'];
  931.         } else if (isset($product_info)) {
  932.             $this->data['tax_class_id'] = $product_info['tax_class_id'];
  933.         } else {
  934.             $this->data['tax_class_id'] = 0;
  935.         }
  936.  
  937.         if (isset($this->request->post['weight'])) {
  938.             $this->data['weight'] = $this->request->post['weight'];
  939.         } else if (isset($product_info)) {
  940.             $this->data['weight'] = $product_info['weight'];
  941.         } else {
  942.             $this->data['weight'] = '';
  943.         }
  944.  
  945.         $this->load->model('localisation/weight_class');
  946.  
  947.         $this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
  948.  
  949.         $weight_info = $this->model_localisation_weight_class->getWeightClassDescriptionByUnit($this->config->get('config_weight_class'));
  950.  
  951.         if (isset($this->request->post['weight_class_id'])) {
  952.             $this->data['weight_class_id'] = $this->request->post['weight_class_id'];
  953.         } elseif (isset($product_info)) {
  954.             $this->data['weight_class_id'] = $product_info['weight_class_id'];
  955.         } elseif (isset($weight_info)) {
  956.             $this->data['weight_class_id'] = $weight_info['weight_class_id'];
  957.         } else {
  958.             $this->data['weight_class_id'] = '';
  959.         }
  960.  
  961.         if (isset($this->request->post['length'])) {
  962.             $this->data['length'] = $this->request->post['length'];
  963.         } elseif (isset($product_info)) {
  964.             $this->data['length'] = $product_info['length'];
  965.         } else {
  966.             $this->data['length'] = '';
  967.         }
  968.  
  969.         if (isset($this->request->post['width'])) {
  970.             $this->data['width'] = $this->request->post['width'];
  971.         } elseif (isset($product_info)) {
  972.             $this->data['width'] = $product_info['width'];
  973.         } else {
  974.             $this->data['width'] = '';
  975.         }
  976.  
  977.         if (isset($this->request->post['height'])) {
  978.             $this->data['height'] = $this->request->post['height'];
  979.         } elseif (isset($product_info)) {
  980.             $this->data['height'] = $product_info['height'];
  981.         } else {
  982.             $this->data['height'] = '';
  983.         }
  984.  
  985.         $this->load->model('localisation/length_class');
  986.  
  987.         $this->data['length_classes'] = $this->model_localisation_length_class->getLengthClasses();
  988.  
  989.         $length_info = $this->model_localisation_length_class->getLengthClassDescriptionByUnit($this->config->get('config_length_class'));
  990.  
  991.         if (isset($this->request->post['length_class_id'])) {
  992.             $this->data['length_class_id'] = $this->request->post['length_class_id'];
  993.         } elseif (isset($product_info)) {
  994.             $this->data['length_class_id'] = $product_info['length_class_id'];
  995.         } elseif (isset($length_info)) {
  996.             $this->data['length_class_id'] = $length_info['length_class_id'];
  997.         } else {
  998.             $this->data['length_class_id'] = '';
  999.         }
  1000.  
  1001.         $this->data['language_id'] = $this->config->get('config_language_id');
  1002.  
  1003.         if (isset($this->request->post['product_option'])) {
  1004.             $this->data['product_options'] = $this->request->post['product_option'];
  1005.         } elseif (isset($product_info)) {
  1006.             $this->data['product_options'] = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
  1007.  
  1008.             //Get current images for preview
  1009.             foreach ($this->data['product_options'] as $option_id => $product_option) { //loop through top level options
  1010.                 foreach ($product_option['product_option_value'] as $option_row => $product_option_value) {
  1011.                     if (!empty($product_option_value['extras']['option_image']) && file_exists(DIR_IMAGE . $product_option_value['extras']['option_image'])) {
  1012.                         $this->data['product_options'][$option_id]['product_option_value'][$option_row]['option_image_preview'] = $this->model_tool_image->resize($product_option_value['extras']['option_image'], 50, 50);
  1013.  
  1014.                     } else {
  1015.                         $this->data['product_options'][$option_id]['product_option_value'][$option_row]['option_image_preview'] = $this->model_tool_image->resize('no_image.jpg', 50, 50);
  1016.                     }
  1017.                 }
  1018.             }
  1019.  
  1020.         } else {
  1021.             $this->data['product_options'] = array();
  1022.         }
  1023.  
  1024. //Textoptions www.alreadymade.com Joseph De Araujo
  1025.         if (isset($this->request->post['product_txtoption'])) {
  1026.             $this->data['product_txtoptions'] = $this->request->post['product_txtoption'];
  1027.         } elseif (isset($product_info)) {
  1028.             $this->data['product_txtoptions'] = $this->model_catalog_product->getProductTxtOptions($this->request->get['product_id']);
  1029.         } else {
  1030.             $this->data['product_txtoptions'] = array();
  1031.         }
  1032. //End Textoptions
  1033.         $this->load->model('sale/customer_group');
  1034.  
  1035.         $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  1036.  
  1037.         if (isset($this->request->post['product_discount'])) {
  1038.             $this->data['product_discounts'] = $this->request->post['product_discount'];
  1039.         } elseif (isset($product_info)) {
  1040.             $this->data['product_discounts'] = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  1041.         } else {
  1042.             $this->data['product_discounts'] = array();
  1043.         }
  1044.  
  1045.         if (isset($this->request->post['product_special'])) {
  1046.             $this->data['product_specials'] = $this->request->post['product_special'];
  1047.         } elseif (isset($product_info)) {
  1048.             $this->data['product_specials'] = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']);
  1049.         } else {
  1050.             $this->data['product_specials'] = array();
  1051.         }
  1052.  
  1053.         $this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 50, 50);
  1054.  
  1055.         $this->data['product_images'] = array();
  1056.  
  1057.         if (isset($product_info)) {
  1058.             $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  1059.  
  1060.             foreach ($results as $result) {
  1061.                 if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
  1062.                     $this->data['product_images'][] = array(
  1063.                         'preview' => $this->model_tool_image->resize($result['image'], 50, 50),
  1064.                         'file'    => $result['image']
  1065.                     );
  1066.                 } else {
  1067.                     $this->data['product_images'][] = array(
  1068.                         'preview' => $this->model_tool_image->resize('no_image.jpg', 50, 50),
  1069.                         'file'    => $result['image']
  1070.                     );
  1071.                 }
  1072.             }
  1073.         }
  1074.  
  1075.         $this->load->model('catalog/download');
  1076.  
  1077.         $this->data['downloads'] = $this->model_catalog_download->getDownloads();
  1078.  
  1079.         if (isset($this->request->post['product_download'])) {
  1080.             $this->data['product_download'] = $this->request->post['product_download'];
  1081.         } elseif (isset($product_info)) {
  1082.             $this->data['product_download'] = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']);
  1083.         } else {
  1084.             $this->data['product_download'] = array();
  1085.         }      
  1086.        
  1087.         $this->load->model('catalog/category');
  1088.  
  1089.         $this->data['categories'] = $this->model_catalog_category->getCategories(0);
  1090.  
  1091.         if (isset($this->request->post['product_category'])) {
  1092.             $this->data['product_category'] = $this->request->post['product_category'];
  1093.         } elseif (isset($product_info)) {
  1094.             $this->data['product_category'] = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
  1095.         } else {
  1096.             $this->data['product_category'] = array();
  1097.         }      
  1098.        
  1099.  
  1100. //Global Mega Options by Joseph De Araujo (Readyman) www.alreadymade.com
  1101.         $this->load->model('catalog/attribute');
  1102.  
  1103.         $this->data['attributes'] = $this->model_catalog_attribute->getAttributes(0);
  1104.  
  1105.         if (isset($this->request->post['product_attribute'])) {
  1106.             $this->data['product_attribute'] = (array)@$this->request->post['product_attribute'];
  1107.         } elseif (isset($product_info)) {
  1108.             $this->data['product_attribute'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
  1109.         } else {
  1110.             $this->data['product_attribute'] = array();
  1111.         }
  1112. //end attributes
  1113.  
  1114.         if (isset($this->request->post['product_related'])) {
  1115.             $this->data['product_related'] = $this->request->post['product_related'];
  1116.         } elseif (isset($product_info)) {
  1117.             $this->data['product_related'] = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  1118.         } else {
  1119.             $this->data['product_related'] = array();
  1120.         }
  1121.  
  1122.         $this->template = 'catalog/product_form.tpl';
  1123.         $this->children = array(
  1124.             'common/header',
  1125.             'common/footer'
  1126.         );
  1127.  
  1128.         $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  1129.     }
  1130.  
  1131.     private function validateForm() {
  1132.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1133.             $this->error['warning'] = $this->language->get('error_permission');
  1134.         }
  1135.  
  1136.         foreach ($this->request->post['product_description'] as $language_id => $value) {
  1137.             if ((strlen(utf8_decode($value['name'])) < 1) || (strlen(utf8_decode($value['name'])) > 255)) {
  1138.                 $this->error['name'][$language_id] = $this->language->get('error_name');
  1139.             }
  1140.         }
  1141.  
  1142.         if ((strlen(utf8_decode($this->request->post['model'])) < 1) || (strlen(utf8_decode($this->request->post['model'])) > 64)) {
  1143.             $this->error['model'] = $this->language->get('error_model');
  1144.         }
  1145.  
  1146.         if (!$this->error) {
  1147.             return TRUE;
  1148.         } else {
  1149.             if (!isset($this->error['warning'])) {
  1150.                 $this->error['warning'] = $this->language->get('error_required_data');
  1151.             }
  1152.             return FALSE;
  1153.         }
  1154.     }
  1155.  
  1156.     private function validateDelete() {
  1157.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1158.             $this->error['warning'] = $this->language->get('error_permission');
  1159.         }
  1160.  
  1161.         if (!$this->error) {
  1162.             return TRUE;
  1163.         } else {
  1164.             return FALSE;
  1165.         }
  1166.     }
  1167.  
  1168.     private function validateCopy() {
  1169.         if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1170.             $this->error['warning'] = $this->language->get('error_permission');
  1171.         }
  1172.  
  1173.         if (!$this->error) {
  1174.             return TRUE;
  1175.         } else {
  1176.             return FALSE;
  1177.         }
  1178.     }
  1179.  
  1180.     public function category() {
  1181.         $this->load->model('catalog/product');
  1182.  
  1183.         if (isset($this->request->get['category_id'])) {
  1184.             $category_id = $this->request->get['category_id'];
  1185.         } else {
  1186.             $category_id = 0;
  1187.         }
  1188.  
  1189.         $product_data = array();
  1190.  
  1191.         $results = $this->model_catalog_product->getProductsByCategoryId($category_id);
  1192.  
  1193.         foreach ($results as $result) {
  1194.             $product_data[] = array(
  1195.                 'product_id' => $result['product_id'],
  1196.                 'name'       => $result['name'],
  1197.                 'model'      => $result['model']
  1198.             );
  1199.         }
  1200.  
  1201.         $this->load->library('json');
  1202.  
  1203.         $this->response->setOutput(Json::encode($product_data));
  1204.     }
  1205.  
  1206.     public function related() {
  1207.         $this->load->model('catalog/product');
  1208.  
  1209.         if (isset($this->request->post['product_related'])) {
  1210.             $products = $this->request->post['product_related'];
  1211.         } else {
  1212.             $products = array();
  1213.         }
  1214.  
  1215.         $product_data = array();
  1216.  
  1217.         foreach ($products as $product_id) {
  1218.             $product_info = $this->model_catalog_product->getProduct($product_id);
  1219.  
  1220.             if ($product_info) {
  1221.                 $product_data[] = array(
  1222.                     'product_id' => $product_info['product_id'],
  1223.                     'name'       => $product_info['name'],
  1224.                     'model'      => $product_info['model']
  1225.                 );
  1226.             }
  1227.         }
  1228.  
  1229.         $this->load->library('json');
  1230.  
  1231.         $this->response->setOutput(Json::encode($product_data));
  1232.     }
  1233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement