poma1

controller cheang

Oct 24th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.58 KB | None | 0 0
  1.  public function change()
  2.     {
  3.         $this->language->load('account/order');
  4.  
  5.         if (isset($this->request->get['order_id'])) {
  6.             $order_id = $this->request->get['order_id'];
  7.         } else {
  8.             $order_id = 0;
  9.         }
  10.  
  11.         if (!$this->customer->isLogged()) {
  12.             $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');
  13.  
  14.             $this->redirect($this->url->link('account/login', '', 'SSL'));
  15.         }
  16.  
  17.         $this->load->model('account/order');
  18.  
  19.         $order_info = $this->model_account_order->getOrder($order_id);
  20.  
  21.         if ($order_info) {
  22.             $this->document->setTitle($this->language->get('text_order'));
  23.  
  24.             $this->data['breadcrumbs'] = array();
  25.  
  26.             $this->data['breadcrumbs'][] = array(
  27.                 'text' => $this->language->get('text_home'),
  28.                 'href' => $this->url->link('common/home'),
  29.                 'separator' => false
  30.             );
  31.  
  32.             $this->data['breadcrumbs'][] = array(
  33.                 'text' => $this->language->get('text_account'),
  34.                 'href' => $this->url->link('account/account', '', 'SSL'),
  35.                 'separator' => $this->language->get('text_separator')
  36.             );
  37.  
  38.             $url = '';
  39.  
  40.             if (isset($this->request->get['page'])) {
  41.                 $url .= '&page=' . $this->request->get['page'];
  42.             }
  43.  
  44.             $this->data['breadcrumbs'][] = array(
  45.                 'text' => $this->language->get('heading_title'),
  46.                 'href' => $this->url->link('account/order', $url, 'SSL'),
  47.                 'separator' => $this->language->get('text_separator')
  48.             );
  49.  
  50.             $this->data['breadcrumbs'][] = array(
  51.                 'text' => $this->language->get('text_order'),
  52.                 'href' => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, 'SSL'),
  53.                 'separator' => $this->language->get('text_separator')
  54.             );
  55.  
  56.             $this->data['heading_title'] = $this->language->get('text_order');
  57.             $this->data['text_order_detail'] = $this->language->get('text_order_detail');
  58.             $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
  59.             $this->data['text_order_id'] = $this->language->get('text_order_id');
  60.             $this->data['text_date_added'] = $this->language->get('text_date_added');
  61.             $this->data['text_post_date'] = $this->language->get('text_post_date');
  62.             $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
  63.             $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
  64.             $this->data['text_payment_method'] = $this->language->get('text_payment_method');
  65.             $this->data['text_payment_address'] = $this->language->get('text_payment_address');
  66.             $this->data['text_history'] = $this->language->get('text_history');
  67.             $this->data['text_comment'] = $this->language->get('text_comment');
  68.             $this->data['column_name'] = $this->language->get('column_name');
  69.             $this->data['column_model'] = $this->language->get('column_model');
  70.             $this->data['column_quantity'] = $this->language->get('column_quantity');
  71.             $this->data['column_price'] = $this->language->get('column_price');
  72.             $this->data['column_total'] = $this->language->get('column_total');
  73.             $this->data['column_action'] = $this->language->get('column_action');
  74.             $this->data['column_date_added'] = $this->language->get('column_date_added');
  75.             $this->data['column_post_date'] = $this->language->get('column_post_date');
  76.             $this->data['column_status'] = $this->language->get('column_status');
  77.             $this->data['column_comment'] = $this->language->get('column_comment');
  78.             $this->data['button_return'] = $this->language->get('button_return');
  79.             $this->data['button_continue'] = $this->language->get('button_continue');
  80.  
  81.             if ($order_info['invoice_no']) {
  82.                 $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  83.             } else {
  84.                 $this->data['invoice_no'] = '';
  85.             }
  86.  
  87.             if ($order_info['sum_']) {
  88.                 $this->data['sum_'] = $order_info['sum_'];
  89.             } else {
  90.                 $this->data['sum_'] = '';
  91.             }
  92.  
  93.             if ($order_info['ttn']) {
  94.                 $this->data['ttn'] = $order_info['ttn'];
  95.             } else {
  96.                 $this->data['ttn'] = '';
  97.             }
  98.  
  99.             $this->data['order_id'] = $this->request->get['order_id'];
  100.             $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
  101.             $this->data['post_date'] = date($this->language->get('date_format_short'), strtotime($order_info['post_date']));
  102.  
  103.  
  104.             if ($order_info['payment_address_format']) {
  105.                 $format = $order_info['payment_address_format'];
  106.             } else {
  107.                 $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  108.             }
  109.  
  110.             $find = array(
  111.                 '{firstname}',
  112.                 '{lastname}',
  113.                 '{company}',
  114.                 '{address_1}',
  115.                 '{address_2}',
  116.                 '{city}',
  117.                 '{postcode}',
  118.                 '{zone}',
  119.                 '{zone_code}',
  120.                 '{country}',
  121.                 '{telephone}'
  122.             );
  123.  
  124.             $replace = array(
  125.                 'firstname' => $order_info['payment_firstname'],
  126.                 'lastname' => $order_info['payment_lastname'],
  127.                 'company' => $order_info['payment_company'],
  128.                 'address_1' => $order_info['payment_address_1'],
  129.                 'address_2' => $order_info['payment_address_2'],
  130.                 'city' => $order_info['payment_city'],
  131.                 'postcode' => $order_info['payment_postcode'],
  132.                 'zone' => $order_info['payment_zone'],
  133.                 'zone_code' => $order_info['payment_zone_code'],
  134.                 'country' => $order_info['payment_country'],
  135.                 'telephone' => $order_info['payment_telephone']
  136.             );
  137.  
  138.             $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
  139.  
  140.             $this->data['payment_method'] = $order_info['payment_method'];
  141.  
  142.             if ($order_info['shipping_address_format']) {
  143.                 $format = $order_info['shipping_address_format'];
  144.             } else {
  145.                 $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}' . "\n" . '{telephone}';
  146.             }
  147.  
  148.             $find = array(
  149.                 '{firstname}',
  150.                 '{lastname}',
  151.                 '{company}',
  152.                 '{address_1}',
  153.                 '{address_2}',
  154.                 '{city}',
  155.                 '{postcode}',
  156.                 '{zone}',
  157.                 '{zone_code}',
  158.                 '{country}',
  159.                 '{telephone}'
  160.             );
  161.  
  162.             $replace = array(
  163.                 'firstname' => $order_info['shipping_firstname'],
  164.                 'lastname' => $order_info['shipping_lastname'],
  165.                 'company' => $order_info['shipping_company'],
  166.                 'address_1' => $order_info['shipping_address_1'],
  167.                 'address_2' => $order_info['shipping_address_2'],
  168.                 'city' => $order_info['shipping_city'],
  169.                 'postcode' => $order_info['shipping_postcode'],
  170.                 'zone' => $order_info['shipping_zone'],
  171.                 'zone_code' => $order_info['shipping_zone_code'],
  172.                 'country' => $order_info['shipping_country'],
  173.                 'telephone' => $order_info['telephone'],
  174.             );
  175.  
  176.             $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
  177.  
  178.             $this->data['shipping_method'] = $order_info['shipping_method'];
  179.  
  180.             $this->data['shipping_firstname'] = ($order_info['shipping_firstname']);
  181.  
  182.             $this->data['shipping_zone'] = ($order_info['shipping_zone']);
  183.  
  184.             $this->data['shipping_city'] = ($order_info['shipping_city']);
  185.             $this->data['payment_address_1'] = ($order_info['payment_address_1']);
  186.             $this->data['telephone'] = ($order_info['telephone']);
  187.  
  188.             if (isset($this->request->post['telephone'])) {
  189.                 $this->data['telephone'] = $this->request->post['telephone'];
  190.             } elseif (!empty($order_info)) {
  191.                 $this->data['telephone'] = $order_info['telephone'];
  192.             } else {
  193.                 $this->data['telephone'] = $this->customer->getTelephone();
  194.             }
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.             $this->data['products'] = array();
  204.  
  205.             $products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
  206.  
  207.             foreach ($products as $product) {
  208.                 $option_data = array();
  209.                 $options = $this->model_account_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
  210.                 foreach ($options as $option) {
  211.                     if ($option['type'] != 'file') {
  212.                         $value = $option['value'];
  213.                     } else {
  214.                         $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
  215.                     }
  216.  
  217.                     $option_data[] = array(
  218.                         'name' => $option['name'],
  219.                         'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
  220.                     );
  221.                 }
  222.                 $this->data['products'][] = array(
  223.                     'name' => $product['name'],
  224.                     'model' => $product['model'],
  225.                     'option' => $option_data,
  226.                     'quantity' => $product['quantity'],
  227.                     'image'    => $product['image'],
  228.                     'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
  229.                     'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
  230.                     'return' => $this->url->link('account/return/insert', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL'),
  231.                     'cancel' => $this->url->link('account/return/insert', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL')
  232.  
  233.                 );
  234.             }
  235.         }
  236.  
  237.  
  238.         $this->language->load('account/return');
  239.  
  240.         $this->load->model('account/order');
  241.  
  242.         if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  243.             $this->model_account_order->updateOrderChange($this->request->get['order_id'], $this->request->post);
  244.  
  245.             $this->redirect($this->url->link('account/order/', '', 'SSL'));
  246.         }
  247.  
  248.  
  249.  
  250.         $this->document->setTitle($this->language->get('Изменить'));
  251.  
  252.  
  253.         $this->data['heading_title'] = $this->language->get('heading_title');
  254.         $this->data['text_description'] = $this->language->get('text_description');
  255.         $this->data['entry_order_id'] = $this->language->get('entry_order_id');
  256.         $this->data['entry_date_ordered'] = $this->language->get('entry_date_ordered');
  257.         $this->data['entry_reason'] = $this->language->get('entry_reason');
  258.         $this->data['entry_fault_detail'] = $this->language->get('entry_fault_detail');
  259.         $this->data['button_continue'] = $this->language->get('button_continue');
  260.         $this->data['button_back'] = $this->language->get('button_back');
  261.  
  262.  
  263.  
  264.         $this->data['zones'] = $this->model_account_order->getOrderZone();
  265.  
  266.         $this->data['regions'] = $this->model_account_order->getCodeNovaposhtaCities();
  267.  
  268.         if(isset($this->request->post['zone'])){
  269.             $this->data['zone'] = $this->request->post['zone'];
  270.  
  271.         }
  272.  
  273.  
  274.  
  275.         if (isset($this->request->post['telephone'])) {
  276.             $this->data['telephone'] = $this->request->post['telephone'];
  277.         } elseif (!empty($order_info)) {
  278.             $this->data['telephone'] = $order_info['telephone'];
  279.         } else {
  280.             $this->data['telephone'] = $this->customer->getTelephone();
  281.         }
  282.  
  283.         if (isset($this->request->post['shipping_firstname'])) {
  284.             $this->data['shipping_firstname'] = $this->request->post['shipping_firstname'];
  285.         } elseif (!empty($order_info)) {
  286.             $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  287.         } else {
  288.             $this->data['shipping_firstname'] = '';
  289.         }
  290.  
  291.         if (isset($this->request->post['shipping_zone'])) {
  292.             $this->data['shipping_zone'] = $this->request->post['shipping_zone'];
  293.         } elseif (!empty($order_info)) {
  294.             $this->data['shipping_zone'] = $order_info['shipping_zone'];
  295.         } else {
  296.             $this->data['shipping_zone'] = '';
  297.         }
  298.         if (isset($this->request->post['shipping_city'])) {
  299.             $this->data['shipping_city'] = $this->request->post['shipping_city'];
  300.         } elseif (!empty($order_info)) {
  301.             $this->data['shipping_city'] = $order_info['shipping_city'];
  302.         } else {
  303.             $this->data['shipping_city'] = '';
  304.         }
  305.         if (isset($this->request->post['payment_address_1'])) {
  306.             $this->data['payment_address_1'] = $this->request->post['payment_address_1'];
  307.         } elseif (!empty($order_info)) {
  308.             $this->data['payment_address_1'] = $order_info['payment_address_1'];
  309.         } else {
  310.             $this->data['payment_address_1'] = '';
  311.         }
  312.  
  313.         /*if (isset($this->error['warning'])) {
  314.             $this->data['error_warning'] = $this->error['warning'];
  315.         } else {
  316.             $this->data['error_warning'] = '';
  317.         }*/
  318.  
  319.         if (isset($this->error['reason'])) {
  320.             $this->data['error_region'] = $this->error['reason'];
  321.         } else {
  322.             $this->data['error_reason'] = '';
  323.         }
  324.  
  325.  
  326.  
  327.         $this->data['action'] = $this->url->link('account/order/change', 'order_id=' . $order_id, 'SSL');
  328.         $this->load->model('localisation/return_reason');
  329.  
  330.  
  331.  
  332.         $this->data['back'] = $this->url->link('account/order', '', 'SSL');
  333.  
  334.         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_change.tpl')) {
  335.             $this->template = $this->config->get('config_template') . '/template/account/order_change.tpl';
  336.         } else {
  337.             $this->template = 'default/template/account/order_change.tpl';
  338.         }
  339.  
  340.         $this->children = array(
  341.             'common/column_left',
  342.             'common/column_right',
  343.             'common/content_top',
  344.             'common/content_bottom',
  345.             'common/footer',
  346.             'common/header'
  347.         );
  348.  
  349.         $this->response->setOutput($this->render());
  350.     }
Advertisement
Add Comment
Please, Sign In to add comment