Skip to content

Instantly share code, notes, and snippets.

@pinguineras
Created March 20, 2014 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinguineras/9668677 to your computer and use it in GitHub Desktop.
Save pinguineras/9668677 to your computer and use it in GitHub Desktop.
Opencart 2.0 - /admin/controller/sale/order.php
<?php
class ControllerSaleOrder extends Controller {
private $error = array();
public function index() {
$this->load->language('sale/order');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('sale/order');
$this->getList();
}
public function franquiados(){
$this->load->language('sale/order');
$this->document->setTitle('Vendas separadas por franquiados');
$this->load->model('sale/order');
$this->getList();
}
public function insert() {
$this->load->language('sale/order');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('sale/order');
$this->getForm();
}
public function update() {
$this->load->language('sale/order');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('sale/order');
$this->getForm();
}
public function delete() {
$this->load->model('sale/order');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateDelete()) {
// $this->model_sale_order->editOrder($this->request->get['order_id']);
if(isset($this->request->post['selected']) && ($this->validateDelete())){
foreach ($this->request->post['selected'] as $order_id) {
$this->model_sale_order->deleteOrder($order_id);
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
}
$this->getList();
}
protected function getList() {
if (isset($this->request->get['filter_order_id'])) {
$filter_order_id = $this->request->get['filter_order_id'];
} else {
$filter_order_id = null;
}
if (isset($this->request->get['filter_customer'])) {
$filter_customer = $this->request->get['filter_customer'];
} else {
$filter_customer = null;
}
if (isset($this->request->get['filter_order_status_id'])) {
$filter_order_status_id = $this->request->get['filter_order_status_id'];
} else {
$filter_order_status_id = null;
}
if (isset($this->request->get['filter_total'])) {
$filter_total = $this->request->get['filter_total'];
} else {
$filter_total = null;
}
if (isset($this->request->get['filter_date_added'])) {
$filter_date_added = $this->request->get['filter_date_added'];
} else {
$filter_date_added = null;
}
if (isset($this->request->get['filter_date_modified'])) {
$filter_date_modified = $this->request->get['filter_date_modified'];
} else {
$filter_date_modified = null;
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'o.order_id';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'DESC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
);
$data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'], 'SSL');
$data['shipping'] = $this->url->link('sale/order/shipping', 'token=' . $this->session->data['token'], 'SSL');
$data['insert'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'], 'SSL');
$data['delete'] = $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
$data['orders'] = array();
$filter_data = array(
'filter_order_id' => $filter_order_id,
'filter_customer' => $filter_customer,
'filter_order_status_id' => $filter_order_status_id,
'filter_total' => $filter_total,
'filter_date_added' => $filter_date_added,
'filter_date_modified' => $filter_date_modified,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
'limit' => $this->config->get('config_limit_admin')
);
$order_total = $this->model_sale_order->getTotalOrders($filter_data);
$results = $this->model_sale_order->getOrders($filter_data);
foreach ($results as $result) {
$data['orders'][] = array(
'order_id' => $result['order_id'],
'customer' => $result['customer'],
'status' => $result['status'],
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
'view' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
'edit' => $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
'expired' => strtotime($result['date_added']) < strtotime('-' . (int)$this->config->get('config_order_edit') . ' day')
);
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_confirm'] = $this->language->get('text_confirm');
$data['text_missing'] = $this->language->get('text_missing');
$data['column_order_id'] = $this->language->get('column_order_id');
$data['column_customer'] = $this->language->get('column_customer');
$data['column_status'] = $this->language->get('column_status');
$data['column_total'] = $this->language->get('column_total');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['column_date_modified'] = $this->language->get('column_date_modified');
$data['column_action'] = $this->language->get('column_action');
$data['entry_return_id'] = $this->language->get('entry_return_id');
$data['entry_order_id'] = $this->language->get('entry_order_id');
$data['entry_customer'] = $this->language->get('entry_customer');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['entry_total'] = $this->language->get('entry_total');
$data['entry_date_added'] = $this->language->get('entry_date_added');
$data['entry_date_modified'] = $this->language->get('entry_date_modified');
$data['button_invoice'] = $this->language->get('button_invoice');
$data['button_shipping'] = $this->language->get('button_shipping');
$data['button_insert'] = $this->language->get('button_insert');
$data['button_edit'] = $this->language->get('button_edit');
$data['button_delete'] = $this->language->get('button_delete');
$data['button_filter'] = $this->language->get('button_filter');
$data['button_view'] = $this->language->get('button_view');
$data['token'] = $this->session->data['token'];
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
if (isset($this->request->post['selected'])) {
$data['selected'] = (array)$this->request->post['selected'];
} else {
$data['selected'] = array();
}
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['sort_order'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.order_id' . $url, 'SSL');
$data['sort_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
$data['sort_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=status' . $url, 'SSL');
$data['sort_total'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.total' . $url, 'SSL');
$data['sort_date_added'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_added' . $url, 'SSL');
$data['sort_date_modified'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_modified' . $url, 'SSL');
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$pagination = new Pagination();
$pagination->total = $order_total;
$pagination->page = $page;
$pagination->limit = $this->config->get('config_limit_admin');
$pagination->url = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_total - $this->config->get('config_limit_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_total, ceil($order_total / $this->config->get('config_limit_admin')));
$data['filter_order_id'] = $filter_order_id;
$data['filter_customer'] = $filter_customer;
$data['filter_order_status_id'] = $filter_order_status_id;
$data['filter_total'] = $filter_total;
$data['filter_date_added'] = $filter_date_added;
$data['filter_date_modified'] = $filter_date_modified;
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
$data['sort'] = $sort;
$data['order'] = $order;
$data['header'] = $this->load->controller('common/header');
$data['menu'] = $this->load->controller('common/menu');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('sale/order_list.tpl', $data));
}
public function getForm() {
$this->load->model('sale/customer');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_default'] = $this->language->get('text_default');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_product'] = $this->language->get('text_product');
$data['text_voucher'] = $this->language->get('text_voucher');
$data['text_order'] = $this->language->get('text_order');
$data['entry_store'] = $this->language->get('entry_store');
$data['entry_customer'] = $this->language->get('entry_customer');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
$data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_comment'] = $this->language->get('entry_comment');
$data['entry_affiliate'] = $this->language->get('entry_affiliate');
$data['entry_address'] = $this->language->get('entry_address');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_zone_code'] = $this->language->get('entry_zone_code');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_product'] = $this->language->get('entry_product');
$data['entry_option'] = $this->language->get('entry_option');
$data['entry_quantity'] = $this->language->get('entry_quantity');
$data['entry_to_name'] = $this->language->get('entry_to_name');
$data['entry_to_email'] = $this->language->get('entry_to_email');
$data['entry_from_name'] = $this->language->get('entry_from_name');
$data['entry_from_email'] = $this->language->get('entry_from_email');
$data['entry_theme'] = $this->language->get('entry_theme');
$data['entry_message'] = $this->language->get('entry_message');
$data['entry_amount'] = $this->language->get('entry_amount');
$data['entry_shipping'] = $this->language->get('entry_shipping');
$data['entry_payment'] = $this->language->get('entry_payment');
$data['entry_voucher'] = $this->language->get('entry_voucher');
$data['entry_coupon'] = $this->language->get('entry_coupon');
$data['entry_reward'] = $this->language->get('entry_reward');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['column_product'] = $this->language->get('column_product');
$data['column_model'] = $this->language->get('column_model');
$data['column_quantity'] = $this->language->get('column_quantity');
$data['column_price'] = $this->language->get('column_price');
$data['column_total'] = $this->language->get('column_total');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_product_add'] = $this->language->get('button_product_add');
$data['button_voucher_add'] = $this->language->get('button_voucher_add');
$data['button_total'] = $this->language->get('button_total');
$data['button_upload'] = $this->language->get('button_upload');
$data['button_remove'] = $this->language->get('button_remove');
$data['tab_order'] = $this->language->get('tab_order');
$data['tab_customer'] = $this->language->get('tab_customer');
$data['tab_payment'] = $this->language->get('tab_payment');
$data['tab_shipping'] = $this->language->get('tab_shipping');
$data['tab_product'] = $this->language->get('tab_product');
$data['tab_voucher'] = $this->language->get('tab_voucher');
$data['tab_total'] = $this->language->get('tab_total');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
if (isset($this->error['lastname'])) {
$data['error_lastname'] = $this->error['lastname'];
} else {
$data['error_lastname'] = '';
}
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['payment_firstname'])) {
$data['error_payment_firstname'] = $this->error['payment_firstname'];
} else {
$data['error_payment_firstname'] = '';
}
if (isset($this->error['payment_lastname'])) {
$data['error_payment_lastname'] = $this->error['payment_lastname'];
} else {
$data['error_payment_lastname'] = '';
}
if (isset($this->error['payment_address_1'])) {
$data['error_payment_address_1'] = $this->error['payment_address_1'];
} else {
$data['error_payment_address_1'] = '';
}
if (isset($this->error['payment_city'])) {
$data['error_payment_city'] = $this->error['payment_city'];
} else {
$data['error_payment_city'] = '';
}
if (isset($this->error['payment_postcode'])) {
$data['error_payment_postcode'] = $this->error['payment_postcode'];
} else {
$data['error_payment_postcode'] = '';
}
if (isset($this->error['payment_country'])) {
$data['error_payment_country'] = $this->error['payment_country'];
} else {
$data['error_payment_country'] = '';
}
if (isset($this->error['payment_zone'])) {
$data['error_payment_zone'] = $this->error['payment_zone'];
} else {
$data['error_payment_zone'] = '';
}
if (isset($this->error['payment_method'])) {
$data['error_payment_method'] = $this->error['payment_method'];
} else {
$data['error_payment_method'] = '';
}
if (isset($this->error['shipping_firstname'])) {
$data['error_shipping_firstname'] = $this->error['shipping_firstname'];
} else {
$data['error_shipping_firstname'] = '';
}
if (isset($this->error['shipping_lastname'])) {
$data['error_shipping_lastname'] = $this->error['shipping_lastname'];
} else {
$data['error_shipping_lastname'] = '';
}
if (isset($this->error['shipping_address_1'])) {
$data['error_shipping_address_1'] = $this->error['shipping_address_1'];
} else {
$data['error_shipping_address_1'] = '';
}
if (isset($this->error['shipping_city'])) {
$data['error_shipping_city'] = $this->error['shipping_city'];
} else {
$data['error_shipping_city'] = '';
}
if (isset($this->error['shipping_postcode'])) {
$data['error_shipping_postcode'] = $this->error['shipping_postcode'];
} else {
$data['error_shipping_postcode'] = '';
}
if (isset($this->error['shipping_country'])) {
$data['error_shipping_country'] = $this->error['shipping_country'];
} else {
$data['error_shipping_country'] = '';
}
if (isset($this->error['shipping_zone'])) {
$data['error_shipping_zone'] = $this->error['shipping_zone'];
} else {
$data['error_shipping_zone'] = '';
}
if (isset($this->error['shipping_method'])) {
$data['error_shipping_method'] = $this->error['shipping_method'];
} else {
$data['error_shipping_method'] = '';
}
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
);
if (!isset($this->request->get['order_id'])) {
$data['action'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
} else {
$data['action'] = $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . $url, 'SSL');
}
$data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
if (isset($this->request->get['order_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
}
$data['token'] = $this->session->data['token'];
if (isset($this->request->get['order_id'])) {
$data['order_id'] = $this->request->get['order_id'];
} else {
$data['order_id'] = 0;
}
if (isset($this->request->post['store_id'])) {
$data['store_id'] = $this->request->post['store_id'];
} elseif (!empty($order_info)) {
$data['store_id'] = $order_info['store_id'];
} else {
$data['store_id'] = '';
}
$this->load->model('setting/store');
$data['stores'] = $this->model_setting_store->getStores();
if ($this->request->server['HTTPS']) {
$data['store_url'] = HTTPS_CATALOG;
} else {
$data['store_url'] = HTTP_CATALOG;
}
if (isset($this->request->post['customer'])) {
$data['customer'] = $this->request->post['customer'];
} elseif (!empty($order_info)) {
$data['customer'] = $order_info['customer'];
} else {
$data['customer'] = '';
}
if (isset($this->request->post['customer_id'])) {
$data['customer_id'] = $this->request->post['customer_id'];
} elseif (!empty($order_info)) {
$data['customer_id'] = $order_info['customer_id'];
} else {
$data['customer_id'] = '';
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} elseif (!empty($order_info)) {
$data['customer_group_id'] = $order_info['customer_group_id'];
} else {
$data['customer_group_id'] = '';
}
$this->load->model('sale/customer_group');
$data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} elseif (!empty($order_info)) {
$data['firstname'] = $order_info['firstname'];
} else {
$data['firstname'] = '';
}
if (isset($this->request->post['lastname'])) {
$data['lastname'] = $this->request->post['lastname'];
} elseif (!empty($order_info)) {
$data['lastname'] = $order_info['lastname'];
} else {
$data['lastname'] = '';
}
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} elseif (!empty($order_info)) {
$data['email'] = $order_info['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} elseif (!empty($order_info)) {
$data['telephone'] = $order_info['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} elseif (!empty($order_info)) {
$data['fax'] = $order_info['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['affiliate_id'])) {
$data['affiliate_id'] = $this->request->post['affiliate_id'];
} elseif (!empty($order_info)) {
$data['affiliate_id'] = $order_info['affiliate_id'];
} else {
$data['affiliate_id'] = '';
}
if (isset($this->request->post['affiliate'])) {
$data['affiliate'] = $this->request->post['affiliate'];
} elseif (!empty($order_info)) {
$data['affiliate'] = ($order_info['affiliate_id'] ? $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname'] : '');
} else {
$data['affiliate'] = '';
}
if (isset($this->request->post['order_status_id'])) {
$data['order_status_id'] = $this->request->post['order_status_id'];
} elseif (!empty($order_info)) {
$data['order_status_id'] = $order_info['order_status_id'];
} else {
$data['order_status_id'] = '';
}
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
if (isset($this->request->post['comment'])) {
$data['comment'] = $this->request->post['comment'];
} elseif (!empty($order_info)) {
$data['comment'] = $order_info['comment'];
} else {
$data['comment'] = '';
}
$this->load->model('sale/customer');
if (isset($this->request->post['customer_id'])) {
$data['addresses'] = $this->model_sale_customer->getAddresses($this->request->post['customer_id']);
} elseif (!empty($order_info)) {
$data['addresses'] = $this->model_sale_customer->getAddresses($order_info['customer_id']);
} else {
$data['addresses'] = array();
}
if (isset($this->request->post['payment_firstname'])) {
$data['payment_firstname'] = $this->request->post['payment_firstname'];
} elseif (!empty($order_info)) {
$data['payment_firstname'] = $order_info['payment_firstname'];
} else {
$data['payment_firstname'] = '';
}
if (isset($this->request->post['payment_lastname'])) {
$data['payment_lastname'] = $this->request->post['payment_lastname'];
} elseif (!empty($order_info)) {
$data['payment_lastname'] = $order_info['payment_lastname'];
} else {
$data['payment_lastname'] = '';
}
if (isset($this->request->post['payment_company'])) {
$data['payment_company'] = $this->request->post['payment_company'];
} elseif (!empty($order_info)) {
$data['payment_company'] = $order_info['payment_company'];
} else {
$data['payment_company'] = '';
}
if (isset($this->request->post['payment_address_1'])) {
$data['payment_address_1'] = $this->request->post['payment_address_1'];
} elseif (!empty($order_info)) {
$data['payment_address_1'] = $order_info['payment_address_1'];
} else {
$data['payment_address_1'] = '';
}
if (isset($this->request->post['payment_address_2'])) {
$data['payment_address_2'] = $this->request->post['payment_address_2'];
} elseif (!empty($order_info)) {
$data['payment_address_2'] = $order_info['payment_address_2'];
} else {
$data['payment_address_2'] = '';
}
if (isset($this->request->post['payment_city'])) {
$data['payment_city'] = $this->request->post['payment_city'];
} elseif (!empty($order_info)) {
$data['payment_city'] = $order_info['payment_city'];
} else {
$data['payment_city'] = '';
}
if (isset($this->request->post['payment_postcode'])) {
$data['payment_postcode'] = $this->request->post['payment_postcode'];
} elseif (!empty($order_info)) {
$data['payment_postcode'] = $order_info['payment_postcode'];
} else {
$data['payment_postcode'] = '';
}
if (isset($this->request->post['payment_country_id'])) {
$data['payment_country_id'] = $this->request->post['payment_country_id'];
} elseif (!empty($order_info)) {
$data['payment_country_id'] = $order_info['payment_country_id'];
} else {
$data['payment_country_id'] = '';
}
if (isset($this->request->post['payment_zone_id'])) {
$data['payment_zone_id'] = $this->request->post['payment_zone_id'];
} elseif (!empty($order_info)) {
$data['payment_zone_id'] = $order_info['payment_zone_id'];
} else {
$data['payment_zone_id'] = '';
}
if (isset($this->request->post['payment_method'])) {
$data['payment_method'] = $this->request->post['payment_method'];
} elseif (!empty($order_info)) {
$data['payment_method'] = $order_info['payment_method'];
} else {
$data['payment_method'] = '';
}
if (isset($this->request->post['payment_code'])) {
$data['payment_code'] = $this->request->post['payment_code'];
} elseif (!empty($order_info)) {
$data['payment_code'] = $order_info['payment_code'];
} else {
$data['payment_code'] = '';
}
if (isset($this->request->post['shipping_firstname'])) {
$data['shipping_firstname'] = $this->request->post['shipping_firstname'];
} elseif (!empty($order_info)) {
$data['shipping_firstname'] = $order_info['shipping_firstname'];
} else {
$data['shipping_firstname'] = '';
}
if (isset($this->request->post['shipping_lastname'])) {
$data['shipping_lastname'] = $this->request->post['shipping_lastname'];
} elseif (!empty($order_info)) {
$data['shipping_lastname'] = $order_info['shipping_lastname'];
} else {
$data['shipping_lastname'] = '';
}
if (isset($this->request->post['shipping_company'])) {
$data['shipping_company'] = $this->request->post['shipping_company'];
} elseif (!empty($order_info)) {
$data['shipping_company'] = $order_info['shipping_company'];
} else {
$data['shipping_company'] = '';
}
if (isset($this->request->post['shipping_address_1'])) {
$data['shipping_address_1'] = $this->request->post['shipping_address_1'];
} elseif (!empty($order_info)) {
$data['shipping_address_1'] = $order_info['shipping_address_1'];
} else {
$data['shipping_address_1'] = '';
}
if (isset($this->request->post['shipping_address_2'])) {
$data['shipping_address_2'] = $this->request->post['shipping_address_2'];
} elseif (!empty($order_info)) {
$data['shipping_address_2'] = $order_info['shipping_address_2'];
} else {
$data['shipping_address_2'] = '';
}
if (isset($this->request->post['shipping_city'])) {
$data['shipping_city'] = $this->request->post['shipping_city'];
} elseif (!empty($order_info)) {
$data['shipping_city'] = $order_info['shipping_city'];
} else {
$data['shipping_city'] = '';
}
if (isset($this->request->post['shipping_postcode'])) {
$data['shipping_postcode'] = $this->request->post['shipping_postcode'];
} elseif (!empty($order_info)) {
$data['shipping_postcode'] = $order_info['shipping_postcode'];
} else {
$data['shipping_postcode'] = '';
}
if (isset($this->request->post['shipping_country_id'])) {
$data['shipping_country_id'] = $this->request->post['shipping_country_id'];
} elseif (!empty($order_info)) {
$data['shipping_country_id'] = $order_info['shipping_country_id'];
} else {
$data['shipping_country_id'] = '';
}
if (isset($this->request->post['shipping_zone_id'])) {
$data['shipping_zone_id'] = $this->request->post['shipping_zone_id'];
} elseif (!empty($order_info)) {
$data['shipping_zone_id'] = $order_info['shipping_zone_id'];
} else {
$data['shipping_zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
if (isset($this->request->post['shipping_method'])) {
$data['shipping_method'] = $this->request->post['shipping_method'];
} elseif (!empty($order_info)) {
$data['shipping_method'] = $order_info['shipping_method'];
} else {
$data['shipping_method'] = '';
}
if (isset($this->request->post['shipping_code'])) {
$data['shipping_code'] = $this->request->post['shipping_code'];
} elseif (!empty($order_info)) {
$data['shipping_code'] = $order_info['shipping_code'];
} else {
$data['shipping_code'] = '';
}
if (isset($this->request->post['order_product'])) {
$order_products = $this->request->post['order_product'];
} elseif (isset($this->request->get['order_id'])) {
$order_products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
} else {
$order_products = array();
}
$this->load->model('catalog/product');
$data['order_products'] = array();
foreach ($order_products as $order_product) {
if (isset($order_product['order_option'])) {
$order_option = $order_product['order_option'];
} elseif (isset($this->request->get['order_id'])) {
$order_option = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $order_product['order_product_id']);
} else {
$order_option = array();
}
$data['order_products'][] = array(
'order_product_id' => $order_product['order_product_id'],
'product_id' => $order_product['product_id'],
'name' => $order_product['name'],
'model' => $order_product['model'],
'option' => $order_option,
'quantity' => $order_product['quantity'],
'price' => $order_product['price'],
'total' => $order_product['total'],
'tax' => $order_product['tax'],
'reward' => $order_product['reward']
);
}
if (isset($this->request->post['order_voucher'])) {
$data['order_vouchers'] = $this->request->post['order_voucher'];
} elseif (isset($this->request->get['order_id'])) {
$data['order_vouchers'] = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
} else {
$data['order_vouchers'] = array();
}
$this->load->model('sale/voucher_theme');
$data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes();
if (isset($this->request->post['order_total'])) {
$order_totals = $this->request->post['order_total'];
} elseif (isset($this->request->get['order_id'])) {
$order_totals = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
} else {
$order_totals = array();
}
$data['coupon'] = '';
$data['voucher'] = '';
$data['reward'] = '';
$data['order_totals'] = array();
foreach ($order_totals as $order_total) {
$data['order_totals'][] = array(
'order_total_id' => $order_total['order_total_id'],
'code' => $order_total['code'],
'title' => $order_total['title'],
'text' => $this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']),
'value' => $order_total['value'],
'sort_order' => $order_total['sort_order']
);
// If coupon, voucher or reward points
$start = strpos($order_total['title'], '(') + 1;
$end = strrpos($order_total['title'], ')');
if ($start && $end) {
if ($order_total['code'] == 'coupon') {
$data['coupon'] = substr($order_total['title'], $start, $end - $start);
}
if ($order_total['code'] == 'voucher') {
$data['voucher'] = substr($order_total['title'], $start, $end - $start);
}
if ($order_total['code'] == 'reward') {
$data['reward'] = substr($order_total['title'], $start, $end - $start);
}
}
}
$data['header'] = $this->load->controller('common/header');
$data['menu'] = $this->load->controller('common/menu');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('sale/order_form.tpl', $data));
}
protected function validateForm() {
if (!$this->user->hasPermission('modify', 'sale/order')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$this->error['lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen($this->request->post['payment_firstname']) < 1) || (utf8_strlen($this->request->post['payment_firstname']) > 32)) {
$this->error['payment_firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen($this->request->post['payment_lastname']) < 1) || (utf8_strlen($this->request->post['payment_lastname']) > 32)) {
$this->error['payment_lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen($this->request->post['payment_address_1']) < 3) || (utf8_strlen($this->request->post['payment_address_1']) > 128)) {
$this->error['payment_address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen($this->request->post['payment_city']) < 3) || (utf8_strlen($this->request->post['payment_city']) > 128)) {
$this->error['payment_city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['payment_postcode']) < 2 || utf8_strlen($this->request->post['payment_postcode']) > 10)) {
$this->error['payment_postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['payment_country_id'] == '') {
$this->error['payment_country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['payment_zone_id']) || $this->request->post['payment_zone_id'] == '') {
$this->error['payment_zone'] = $this->language->get('error_zone');
}
if (!isset($this->request->post['payment_method']) || $this->request->post['payment_method'] == '') {
$this->error['payment_method'] = $this->language->get('error_payment');
}
// Check if any products require shipping
$shipping = false;
if (isset($this->request->post['order_product'])) {
$this->load->model('catalog/product');
foreach ($this->request->post['order_product'] as $order_product) {
$product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
if ($product_info && $product_info['shipping']) {
$shipping = true;
break;
}
}
}
if ($shipping) {
if ((utf8_strlen($this->request->post['shipping_firstname']) < 1) || (utf8_strlen($this->request->post['shipping_firstname']) > 32)) {
$this->error['shipping_firstname'] = $this->language->get('error_firstname');
}
if ((utf8_strlen($this->request->post['shipping_lastname']) < 1) || (utf8_strlen($this->request->post['shipping_lastname']) > 32)) {
$this->error['shipping_lastname'] = $this->language->get('error_lastname');
}
if ((utf8_strlen($this->request->post['shipping_address_1']) < 3) || (utf8_strlen($this->request->post['shipping_address_1']) > 128)) {
$this->error['shipping_address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen($this->request->post['shipping_city']) < 3) || (utf8_strlen($this->request->post['shipping_city']) > 128)) {
$this->error['shipping_city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2 || utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
$this->error['shipping_postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['shipping_country_id'] == '') {
$this->error['shipping_country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['shipping_zone_id']) || $this->request->post['shipping_zone_id'] == '') {
$this->error['shipping_zone'] = $this->language->get('error_zone');
}
if (!$this->request->post['shipping_method']) {
$this->error['shipping_method'] = $this->language->get('error_shipping');
}
}
if ($this->error && !isset($this->error['warning'])) {
$this->error['warning'] = $this->language->get('error_warning');
}
return !$this->error;
}
protected function validateDelete() {
if (!$this->user->hasPermission('modify', 'sale/order')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
public function country() {
$json = array();
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
if ($country_info) {
$this->load->model('localisation/zone');
$json = array(
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'iso_code_2' => $country_info['iso_code_2'],
'iso_code_3' => $country_info['iso_code_3'],
'address_format' => $country_info['address_format'],
'postcode_required' => $country_info['postcode_required'],
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
'status' => $country_info['status']
);
}
$this->response->setOutput(json_encode($json));
}
public function info() {
$this->load->model('sale/order');
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->load->language('sale/order');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['text_order_id'] = $this->language->get('text_order_id');
$data['text_invoice_no'] = $this->language->get('text_invoice_no');
$data['text_invoice_date'] = $this->language->get('text_invoice_date');
$data['text_store_name'] = $this->language->get('text_store_name');
$data['text_store_url'] = $this->language->get('text_store_url');
$data['text_customer'] = $this->language->get('text_customer');
$data['text_customer_group'] = $this->language->get('text_customer_group');
$data['text_email'] = $this->language->get('text_email');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_total'] = $this->language->get('text_total');
$data['text_reward'] = $this->language->get('text_reward');
$data['text_order_status'] = $this->language->get('text_order_status');
$data['text_comment'] = $this->language->get('text_comment');
$data['text_affiliate'] = $this->language->get('text_affiliate');
$data['text_commission'] = $this->language->get('text_commission');
$data['text_ip'] = $this->language->get('text_ip');
$data['text_forwarded_ip'] = $this->language->get('text_forwarded_ip');
$data['text_user_agent'] = $this->language->get('text_user_agent');
$data['text_accept_language'] = $this->language->get('text_accept_language');
$data['text_date_added'] = $this->language->get('text_date_added');
$data['text_date_modified'] = $this->language->get('text_date_modified');
$data['text_firstname'] = $this->language->get('text_firstname');
$data['text_lastname'] = $this->language->get('text_lastname');
$data['text_company'] = $this->language->get('text_company');
$data['text_address_1'] = $this->language->get('text_address_1');
$data['text_address_2'] = $this->language->get('text_address_2');
$data['text_city'] = $this->language->get('text_city');
$data['text_postcode'] = $this->language->get('text_postcode');
$data['text_zone'] = $this->language->get('text_zone');
$data['text_zone_code'] = $this->language->get('text_zone_code');
$data['text_country'] = $this->language->get('text_country');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['text_payment_method'] = $this->language->get('text_payment_method');
$data['text_country_match'] = $this->language->get('text_country_match');
$data['text_country_code'] = $this->language->get('text_country_code');
$data['text_high_risk_country'] = $this->language->get('text_high_risk_country');
$data['text_distance'] = $this->language->get('text_distance');
$data['text_ip_region'] = $this->language->get('text_ip_region');
$data['text_ip_city'] = $this->language->get('text_ip_city');
$data['text_ip_latitude'] = $this->language->get('text_ip_latitude');
$data['text_ip_longitude'] = $this->language->get('text_ip_longitude');
$data['text_ip_isp'] = $this->language->get('text_ip_isp');
$data['text_ip_org'] = $this->language->get('text_ip_org');
$data['text_ip_asnum'] = $this->language->get('text_ip_asnum');
$data['text_ip_user_type'] = $this->language->get('text_ip_user_type');
$data['text_ip_country_confidence'] = $this->language->get('text_ip_country_confidence');
$data['text_ip_region_confidence'] = $this->language->get('text_ip_region_confidence');
$data['text_ip_city_confidence'] = $this->language->get('text_ip_city_confidence');
$data['text_ip_postal_confidence'] = $this->language->get('text_ip_postal_confidence');
$data['text_ip_postal_code'] = $this->language->get('text_ip_postal_code');
$data['text_ip_accuracy_radius'] = $this->language->get('text_ip_accuracy_radius');
$data['text_ip_net_speed_cell'] = $this->language->get('text_ip_net_speed_cell');
$data['text_ip_metro_code'] = $this->language->get('text_ip_metro_code');
$data['text_ip_area_code'] = $this->language->get('text_ip_area_code');
$data['text_ip_time_zone'] = $this->language->get('text_ip_time_zone');
$data['text_ip_region_name'] = $this->language->get('text_ip_region_name');
$data['text_ip_domain'] = $this->language->get('text_ip_domain');
$data['text_ip_country_name'] = $this->language->get('text_ip_country_name');
$data['text_ip_continent_code'] = $this->language->get('text_ip_continent_code');
$data['text_ip_corporate_proxy'] = $this->language->get('text_ip_corporate_proxy');
$data['text_anonymous_proxy'] = $this->language->get('text_anonymous_proxy');
$data['text_proxy_score'] = $this->language->get('text_proxy_score');
$data['text_is_trans_proxy'] = $this->language->get('text_is_trans_proxy');
$data['text_free_mail'] = $this->language->get('text_free_mail');
$data['text_carder_email'] = $this->language->get('text_carder_email');
$data['text_high_risk_username'] = $this->language->get('text_high_risk_username');
$data['text_high_risk_password'] = $this->language->get('text_high_risk_password');
$data['text_bin_match'] = $this->language->get('text_bin_match');
$data['text_bin_country'] = $this->language->get('text_bin_country');
$data['text_bin_name_match'] = $this->language->get('text_bin_name_match');
$data['text_bin_name'] = $this->language->get('text_bin_name');
$data['text_bin_phone_match'] = $this->language->get('text_bin_phone_match');
$data['text_bin_phone'] = $this->language->get('text_bin_phone');
$data['text_customer_phone_in_billing_location'] = $this->language->get('text_customer_phone_in_billing_location');
$data['text_ship_forward'] = $this->language->get('text_ship_forward');
$data['text_city_postal_match'] = $this->language->get('text_city_postal_match');
$data['text_ship_city_postal_match'] = $this->language->get('text_ship_city_postal_match');
$data['text_score'] = $this->language->get('text_score');
$data['text_explanation'] = $this->language->get('text_explanation');
$data['text_risk_score'] = $this->language->get('text_risk_score');
$data['text_queries_remaining'] = $this->language->get('text_queries_remaining');
$data['text_maxmind_id'] = $this->language->get('text_maxmind_id');
$data['text_error'] = $this->language->get('text_error');
$data['help_country_match'] = $this->language->get('help_country_match');
$data['help_country_code'] = $this->language->get('help_country_code');
$data['help_high_risk_country'] = $this->language->get('help_high_risk_country');
$data['help_distance'] = $this->language->get('help_distance');
$data['help_ip_region'] = $this->language->get('help_ip_region');
$data['help_ip_city'] = $this->language->get('help_ip_city');
$data['help_ip_latitude'] = $this->language->get('help_ip_latitude');
$data['help_ip_longitude'] = $this->language->get('help_ip_longitude');
$data['help_ip_isp'] = $this->language->get('help_ip_isp');
$data['help_ip_org'] = $this->language->get('help_ip_org');
$data['help_ip_asnum'] = $this->language->get('help_ip_asnum');
$data['help_ip_user_type'] = $this->language->get('help_ip_user_type');
$data['help_ip_country_confidence'] = $this->language->get('help_ip_country_confidence');
$data['help_ip_region_confidence'] = $this->language->get('help_ip_region_confidence');
$data['help_ip_city_confidence'] = $this->language->get('help_ip_city_confidence');
$data['help_ip_postal_confidence'] = $this->language->get('help_ip_postal_confidence');
$data['help_ip_postal_code'] = $this->language->get('help_ip_postal_code');
$data['help_ip_accuracy_radius'] = $this->language->get('help_ip_accuracy_radius');
$data['help_ip_net_speed_cell'] = $this->language->get('help_ip_net_speed_cell');
$data['help_ip_metro_code'] = $this->language->get('help_ip_metro_code');
$data['help_ip_area_code'] = $this->language->get('help_ip_area_code');
$data['help_ip_time_zone'] = $this->language->get('help_ip_time_zone');
$data['help_ip_region_name'] = $this->language->get('help_ip_region_name');
$data['help_ip_domain'] = $this->language->get('help_ip_domain');
$data['help_ip_country_name'] = $this->language->get('help_ip_country_name');
$data['help_ip_continent_code'] = $this->language->get('help_ip_continent_code');
$data['help_ip_corporate_proxy'] = $this->language->get('help_ip_corporate_proxy');
$data['help_anonymous_proxy'] = $this->language->get('help_anonymous_proxy');
$data['help_proxy_score'] = $this->language->get('help_proxy_score');
$data['help_is_trans_proxy'] = $this->language->get('help_is_trans_proxy');
$data['help_free_mail'] = $this->language->get('help_free_mail');
$data['help_carder_email'] = $this->language->get('help_carder_email');
$data['help_high_risk_username'] = $this->language->get('help_high_risk_username');
$data['help_high_risk_password'] = $this->language->get('help_high_risk_password');
$data['help_bin_match'] = $this->language->get('help_bin_match');
$data['help_bin_country'] = $this->language->get('help_bin_country');
$data['help_bin_name_match'] = $this->language->get('help_bin_name_match');
$data['help_bin_name'] = $this->language->get('help_bin_name');
$data['help_bin_phone_match'] = $this->language->get('help_bin_phone_match');
$data['help_bin_phone'] = $this->language->get('help_bin_phone');
$data['help_customer_phone_in_billing_location'] = $this->language->get('help_customer_phone_in_billing_location');
$data['help_ship_forward'] = $this->language->get('help_ship_forward');
$data['help_city_postal_match'] = $this->language->get('help_city_postal_match');
$data['help_ship_city_postal_match'] = $this->language->get('help_ship_city_postal_match');
$data['help_score'] = $this->language->get('help_score');
$data['help_explanation'] = $this->language->get('help_explanation');
$data['help_risk_score'] = $this->language->get('help_risk_score');
$data['help_queries_remaining'] = $this->language->get('help_queries_remaining');
$data['help_maxmind_id'] = $this->language->get('help_maxmind_id');
$data['help_error'] = $this->language->get('help_error');
$data['column_product'] = $this->language->get('column_product');
$data['column_model'] = $this->language->get('column_model');
$data['column_quantity'] = $this->language->get('column_quantity');
$data['column_price'] = $this->language->get('column_price');
$data['column_total'] = $this->language->get('column_total');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['entry_notify'] = $this->language->get('entry_notify');
$data['entry_comment'] = $this->language->get('entry_comment');
$data['button_invoice'] = $this->language->get('button_invoice');
$data['button_restock'] = $this->language->get('button_restock');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_generate'] = $this->language->get('button_generate');
$data['button_reward_add'] = $this->language->get('button_reward_add');
$data['button_reward_remove'] = $this->language->get('button_reward_remove');
$data['button_commission_add'] = $this->language->get('button_commission_add');
$data['button_commission_remove'] = $this->language->get('button_commission_remove');
$data['button_history_add'] = $this->language->get('button_history_add');
$data['tab_order'] = $this->language->get('tab_order');
$data['tab_payment'] = $this->language->get('tab_payment');
$data['tab_shipping'] = $this->language->get('tab_shipping');
$data['tab_product'] = $this->language->get('tab_product');
$data['tab_history'] = $this->language->get('tab_history');
$data['tab_fraud'] = $this->language->get('tab_fraud');
$data['token'] = $this->session->data['token'];
$url = '';
if (isset($this->request->get['filter_order_id'])) {
$url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
}
if (isset($this->request->get['filter_customer'])) {
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_order_status_id'])) {
$url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
}
if (isset($this->request->get['filter_total'])) {
$url .= '&filter_total=' . $this->request->get['filter_total'];
}
if (isset($this->request->get['filter_date_added'])) {
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
}
if (isset($this->request->get['filter_date_modified'])) {
$url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
);
$data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], 'SSL');
$data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
$data['order_id'] = $this->request->get['order_id'];
if ($order_info['invoice_no']) {
$data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$data['invoice_no'] = '';
}
$data['store_name'] = $order_info['store_name'];
$data['store_url'] = $order_info['store_url'];
$data['firstname'] = $order_info['firstname'];
$data['lastname'] = $order_info['lastname'];
if ($order_info['customer_id']) {
$data['customer'] = $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $order_info['customer_id'], 'SSL');
} else {
$data['customer'] = '';
}
$this->load->model('sale/customer_group');
$customer_group_info = $this->model_sale_customer_group->getCustomerGroup($order_info['customer_group_id']);
if ($customer_group_info) {
$data['customer_group'] = $customer_group_info['name'];
} else {
$data['customer_group'] = '';
}
$data['email'] = $order_info['email'];
$data['telephone'] = $order_info['telephone'];
$data['fax'] = $order_info['fax'];
$data['comment'] = nl2br($order_info['comment']);
$data['shipping_method'] = $order_info['shipping_method'];
$data['payment_method'] = $order_info['payment_method'];
$data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value']);
$this->load->model('sale/customer');
$data['reward'] = $order_info['reward'];
$data['reward_total'] = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
$data['affiliate_firstname'] = $order_info['affiliate_firstname'];
$data['affiliate_lastname'] = $order_info['affiliate_lastname'];
if ($order_info['affiliate_id']) {
$data['affiliate'] = $this->url->link('marketing/affiliate/update', 'token=' . $this->session->data['token'] . '&affiliate_id=' . $order_info['affiliate_id'], 'SSL');
} else {
$data['affiliate'] = '';
}
$data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']);
$this->load->model('marketing/affiliate');
$data['commission_total'] = $this->model_marketing_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
$this->load->model('localisation/order_status');
$order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
if ($order_status_info) {
$data['order_status'] = $order_status_info['name'];
} else {
$data['order_status'] = '';
}
$data['ip'] = $order_info['ip'];
$data['forwarded_ip'] = $order_info['forwarded_ip'];
$data['user_agent'] = $order_info['user_agent'];
$data['accept_language'] = $order_info['accept_language'];
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
$data['date_modified'] = date($this->language->get('date_format_short'), strtotime($order_info['date_modified']));
$data['payment_firstname'] = $order_info['payment_firstname'];
$data['payment_lastname'] = $order_info['payment_lastname'];
$data['payment_company'] = $order_info['payment_company'];
$data['payment_address_1'] = $order_info['payment_address_1'];
$data['payment_address_2'] = $order_info['payment_address_2'];
$data['payment_city'] = $order_info['payment_city'];
$data['payment_postcode'] = $order_info['payment_postcode'];
$data['payment_zone'] = $order_info['payment_zone'];
$data['payment_zone_code'] = $order_info['payment_zone_code'];
$data['payment_country'] = $order_info['payment_country'];
$data['shipping_firstname'] = $order_info['shipping_firstname'];
$data['shipping_lastname'] = $order_info['shipping_lastname'];
$data['shipping_company'] = $order_info['shipping_company'];
$data['shipping_address_1'] = $order_info['shipping_address_1'];
$data['shipping_address_2'] = $order_info['shipping_address_2'];
$data['shipping_city'] = $order_info['shipping_city'];
$data['shipping_postcode'] = $order_info['shipping_postcode'];
$data['shipping_zone'] = $order_info['shipping_zone'];
$data['shipping_zone_code'] = $order_info['shipping_zone_code'];
$data['shipping_country'] = $order_info['shipping_country'];
$data['products'] = array();
$products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
foreach ($products as $product) {
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$option_data[] = array(
'name' => $option['name'],
'value' => $option['value'],
'type' => $option['type']
);
} else {
$option_data[] = array(
'name' => $option['name'],
'value' => utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')),
'type' => $option['type'],
'href' => $this->url->link('sale/order/download', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&order_option_id=' . $option['order_option_id'], 'SSL')
);
}
}
$data['products'][] = array(
'order_product_id' => $product['order_product_id'],
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $product['product_id'], 'SSL')
);
}
$data['vouchers'] = array();
$vouchers = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
foreach ($vouchers as $voucher) {
$data['vouchers'][] = array(
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']),
'href' => $this->url->link('sale/voucher/update', 'token=' . $this->session->data['token'] . '&voucher_id=' . $voucher['voucher_id'], 'SSL')
);
}
$totals = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
foreach ($totals as $total) {
$data['totals'][] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
);
}
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
$data['order_status_id'] = $order_info['order_status_id'];
// Fraud
$this->load->model('sale/fraud');
$fraud_info = $this->model_sale_fraud->getFraud($order_info['order_id']);
if ($fraud_info) {
$data['country_match'] = $fraud_info['country_match'];
if ($fraud_info['country_code']) {
$data['country_code'] = $fraud_info['country_code'];
} else {
$data['country_code'] = '';
}
$data['high_risk_country'] = $fraud_info['high_risk_country'];
$data['distance'] = $fraud_info['distance'];
if ($fraud_info['ip_region']) {
$data['ip_region'] = $fraud_info['ip_region'];
} else {
$data['ip_region'] = '';
}
if ($fraud_info['ip_city']) {
$data['ip_city'] = $fraud_info['ip_city'];
} else {
$data['ip_city'] = '';
}
$data['ip_latitude'] = $fraud_info['ip_latitude'];
$data['ip_longitude'] = $fraud_info['ip_longitude'];
if ($fraud_info['ip_isp']) {
$data['ip_isp'] = $fraud_info['ip_isp'];
} else {
$data['ip_isp'] = '';
}
if ($fraud_info['ip_org']) {
$data['ip_org'] = $fraud_info['ip_org'];
} else {
$data['ip_org'] = '';
}
$data['ip_asnum'] = $fraud_info['ip_asnum'];
if ($fraud_info['ip_user_type']) {
$data['ip_user_type'] = $fraud_info['ip_user_type'];
} else {
$data['ip_user_type'] = '';
}
if ($fraud_info['ip_country_confidence']) {
$data['ip_country_confidence'] = $fraud_info['ip_country_confidence'];
} else {
$data['ip_country_confidence'] = '';
}
if ($fraud_info['ip_region_confidence']) {
$data['ip_region_confidence'] = $fraud_info['ip_region_confidence'];
} else {
$data['ip_region_confidence'] = '';
}
if ($fraud_info['ip_city_confidence']) {
$data['ip_city_confidence'] = $fraud_info['ip_city_confidence'];
} else {
$data['ip_city_confidence'] = '';
}
if ($fraud_info['ip_postal_confidence']) {
$data['ip_postal_confidence'] = $fraud_info['ip_postal_confidence'];
} else {
$data['ip_postal_confidence'] = '';
}
if ($fraud_info['ip_postal_code']) {
$data['ip_postal_code'] = $fraud_info['ip_postal_code'];
} else {
$data['ip_postal_code'] = '';
}
$data['ip_accuracy_radius'] = $fraud_info['ip_accuracy_radius'];
if ($fraud_info['ip_net_speed_cell']) {
$data['ip_net_speed_cell'] = $fraud_info['ip_net_speed_cell'];
} else {
$data['ip_net_speed_cell'] = '';
}
$data['ip_metro_code'] = $fraud_info['ip_metro_code'];
$data['ip_area_code'] = $fraud_info['ip_area_code'];
if ($fraud_info['ip_time_zone']) {
$data['ip_time_zone'] = $fraud_info['ip_time_zone'];
} else {
$data['ip_time_zone'] = '';
}
if ($fraud_info['ip_region_name']) {
$data['ip_region_name'] = $fraud_info['ip_region_name'];
} else {
$data['ip_region_name'] = '';
}
if ($fraud_info['ip_domain']) {
$data['ip_domain'] = $fraud_info['ip_domain'];
} else {
$data['ip_domain'] = '';
}
if ($fraud_info['ip_country_name']) {
$data['ip_country_name'] = $fraud_info['ip_country_name'];
} else {
$data['ip_country_name'] = '';
}
if ($fraud_info['ip_continent_code']) {
$data['ip_continent_code'] = $fraud_info['ip_continent_code'];
} else {
$data['ip_continent_code'] = '';
}
if ($fraud_info['ip_corporate_proxy']) {
$data['ip_corporate_proxy'] = $fraud_info['ip_corporate_proxy'];
} else {
$data['ip_corporate_proxy'] = '';
}
$data['anonymous_proxy'] = $fraud_info['anonymous_proxy'];
$data['proxy_score'] = $fraud_info['proxy_score'];
if ($fraud_info['is_trans_proxy']) {
$data['is_trans_proxy'] = $fraud_info['is_trans_proxy'];
} else {
$data['is_trans_proxy'] = '';
}
$data['free_mail'] = $fraud_info['free_mail'];
$data['carder_email'] = $fraud_info['carder_email'];
if ($fraud_info['high_risk_username']) {
$data['high_risk_username'] = $fraud_info['high_risk_username'];
} else {
$data['high_risk_username'] = '';
}
if ($fraud_info['high_risk_password']) {
$data['high_risk_password'] = $fraud_info['high_risk_password'];
} else {
$data['high_risk_password'] = '';
}
$data['bin_match'] = $fraud_info['bin_match'];
if ($fraud_info['bin_country']) {
$data['bin_country'] = $fraud_info['bin_country'];
} else {
$data['bin_country'] = '';
}
$data['bin_name_match'] = $fraud_info['bin_name_match'];
if ($fraud_info['bin_name']) {
$data['bin_name'] = $fraud_info['bin_name'];
} else {
$data['bin_name'] = '';
}
$data['bin_phone_match'] = $fraud_info['bin_phone_match'];
if ($fraud_info['bin_phone']) {
$data['bin_phone'] = $fraud_info['bin_phone'];
} else {
$data['bin_phone'] = '';
}
if ($fraud_info['customer_phone_in_billing_location']) {
$data['customer_phone_in_billing_location'] = $fraud_info['customer_phone_in_billing_location'];
} else {
$data['customer_phone_in_billing_location'] = '';
}
$data['ship_forward'] = $fraud_info['ship_forward'];
if ($fraud_info['city_postal_match']) {
$data['city_postal_match'] = $fraud_info['city_postal_match'];
} else {
$data['city_postal_match'] = '';
}
if ($fraud_info['ship_city_postal_match']) {
$data['ship_city_postal_match'] = $fraud_info['ship_city_postal_match'];
} else {
$data['ship_city_postal_match'] = '';
}
$data['score'] = $fraud_info['score'];
$data['explanation'] = $fraud_info['explanation'];
$data['risk_score'] = $fraud_info['risk_score'];
$data['queries_remaining'] = $fraud_info['queries_remaining'];
$data['maxmind_id'] = $fraud_info['maxmind_id'];
$data['error'] = $fraud_info['error'];
} else {
$data['maxmind_id'] = '';
}
$data['payment_action'] = $this->load->controller('payment/' . $order_info['payment_code'] . '/orderAction', '');
$data['header'] = $this->load->controller('common/header');
$data['menu'] = $this->load->controller('common/menu');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('sale/order_info.tpl', $data));
} else {
$this->load->language('error/not_found');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['text_not_found'] = $this->language->get('text_not_found');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL')
);
$data['header'] = $this->load->controller('common/header');
$data['menu'] = $this->load->controller('common/menu');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('error/not_found.tpl', $data));
}
}
public function createInvoiceNo() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} elseif (isset($this->request->get['order_id'])) {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$invoice_no = $this->model_sale_order->createInvoiceNo($order_id);
if ($invoice_no) {
$json['invoice_no'] = $invoice_no;
} else {
$json['error'] = $this->language->get('error_action');
}
}
$this->response->setOutput(json_encode($json));
}
public function addReward() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info && $order_info['customer_id'] && ($order_info['reward'] > 0)) {
$this->load->model('sale/customer');
$reward_total = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($order_id);
if (!$reward_total) {
$this->model_sale_customer->addReward($order_info['customer_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['reward'], $order_id);
}
}
$json['success'] = $this->language->get('text_reward_added');
}
$this->response->setOutput(json_encode($json));
}
public function removeReward() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->load->model('sale/customer');
$this->model_sale_customer->deleteReward($order_id);
}
$json['success'] = $this->language->get('text_reward_removed');
}
$this->response->setOutput(json_encode($json));
}
public function addCommission() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->load->model('marketing/affiliate');
$affiliate_total = $this->model_marketing_affiliate->getTotalTransactionsByOrderId($order_id);
if (!$affiliate_total) {
$this->model_marketing_affiliate->addTransaction($order_info['affiliate_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['commission'], $order_id);
}
}
$json['success'] = $this->language->get('text_commission_added');
}
$this->response->setOutput(json_encode($json));
}
public function removeCommission() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->load->model('marketing/affiliate');
$this->model_marketing_affiliate->deleteTransaction($order_id);
}
$json['success'] = $this->language->get('text_commission_removed');
}
$this->response->setOutput(json_encode($json));
}
public function restock() {
$this->load->language('sale/order');
$json = array();
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['order_id'])) {
$order_id = $this->request->get['order_id'];
} else {
$order_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->model_sale_order->restock($this->request->get['order_id']);
$json['success'] = $this->language->get('text_restock');
}
}
$this->response->setOutput(json_encode($json));
}
public function history() {
$this->load->language('sale/order');
$data['error'] = '';
$data['success'] = '';
$this->load->model('sale/order');
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
if (!$this->user->hasPermission('modify', 'sale/order')) {
$data['error'] = $this->language->get('error_permission');
}
if (!$data['error']) {
$this->model_sale_order->addOrderHistory($this->request->get['order_id'], $this->request->post);
$data['success'] = $this->language->get('text_success');
}
}
$data['text_no_results'] = $this->language->get('text_no_results');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['column_status'] = $this->language->get('column_status');
$data['column_notify'] = $this->language->get('column_notify');
$data['column_comment'] = $this->language->get('column_comment');
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$data['histories'] = array();
$results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10);
foreach ($results as $result) {
$data['histories'][] = array(
'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
'status' => $result['status'],
'comment' => nl2br($result['comment']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
$history_total = $this->model_sale_order->getTotalOrderHistories($this->request->get['order_id']);
$pagination = new Pagination();
$pagination->total = $history_total;
$pagination->page = $page;
$pagination->limit = 10;
$pagination->url = $this->url->link('sale/order/history', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', 'SSL');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($history_total - $this->config->get('config_limit_admin'))) ? $history_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $history_total, ceil($history_total / $this->config->get('config_limit_admin')));
$this->response->setOutput($this->load->view('sale/order_history.tpl', $data));
}
public function download() {
$this->load->model('sale/order');
if (isset($this->request->get['order_option_id'])) {
$order_option_id = $this->request->get['order_option_id'];
} else {
$order_option_id = 0;
}
$option_info = $this->model_sale_order->getOrderOption($this->request->get['order_id'], $order_option_id);
if ($option_info && $option_info['type'] == 'file') {
$file = DIR_DOWNLOAD . $option_info['value'];
$mask = basename(utf8_substr($option_info['value'], 0, utf8_strrpos($option_info['value'], '.')));
if (!headers_sent()) {
if (is_file($file)) {
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file, 'rb');
exit;
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->load->language('error/not_found');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['text_not_found'] = $this->language->get('text_not_found');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL')
);
$data['header'] = $this->load->controller('common/header');
$data['menu'] = $this->load->controller('common/menu');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('error/not_found.tpl', $data));
}
}
public function upload() {
$this->load->language('sale/order');
$json = array();
// Check user has permission
if (!$this->user->hasPermission('modify', 'sale/order')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
if (!empty($this->request->files['file']['name'])) {
// Sanitize the filename
$filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 128)) {
$json['error'] = $this->language->get('error_filename');
}
// Allowed file extension types
$allowed = array();
$extension_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_extension_allowed'));
$filetypes = explode("\n", $extension_allowed);
foreach ($filetypes as $filetype) {
$allowed[] = trim($filetype);
}
if (!in_array(strtolower(substr(strrchr($filename, '.'), 1)), $allowed)) {
$json['error'] = $this->language->get('error_filetype');
}
// Allowed file mime types
$allowed = array();
$mime_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_mime_allowed'));
$filetypes = explode("\n", $mime_allowed);
foreach ($filetypes as $filetype) {
$allowed[] = trim($filetype);
}
if (!in_array($this->request->files['file']['type'], $allowed)) {
$json['error'] = $this->language->get('error_filetype');
}
// Return any upload error
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
}
} else {
$json['error'] = $this->language->get('error_upload');
}
}
if (!$json) {
$file = $filename . '.' . md5(mt_rand());
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
$json['file'] = $file;
$json['success'] = $this->language->get('text_upload');
}
$this->response->setOutput(json_encode($json));
}
public function invoice() {
$this->load->language('sale/order');
$data['title'] = $this->language->get('text_invoice');
if ($this->request->server['HTTPS']) {
$data['base'] = HTTPS_SERVER;
} else {
$data['base'] = HTTP_SERVER;
}
$data['direction'] = $this->language->get('direction');
$data['lang'] = $this->language->get('code');
$data['text_invoice'] = $this->language->get('text_invoice');
$data['text_order_detail'] = $this->language->get('text_order_detail');
$data['text_order_id'] = $this->language->get('text_order_id');
$data['text_invoice_no'] = $this->language->get('text_invoice_no');
$data['text_invoice_date'] = $this->language->get('text_invoice_date');
$data['text_date_added'] = $this->language->get('text_date_added');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_email'] = $this->language->get('text_email');
$data['text_website'] = $this->language->get('text_website');
$data['text_to'] = $this->language->get('text_to');
$data['text_ship_to'] = $this->language->get('text_ship_to');
$data['text_payment_method'] = $this->language->get('text_payment_method');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['column_product'] = $this->language->get('column_product');
$data['column_model'] = $this->language->get('column_model');
$data['column_quantity'] = $this->language->get('column_quantity');
$data['column_price'] = $this->language->get('column_price');
$data['column_total'] = $this->language->get('column_total');
$data['column_comment'] = $this->language->get('column_comment');
$this->load->model('sale/order');
$this->load->model('setting/setting');
$data['orders'] = array();
$orders = array();
if (isset($this->request->post['selected'])) {
$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
$orders[] = $this->request->get['order_id'];
}
foreach ($orders as $order_id) {
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
if ($store_info) {
$store_address = $store_info['config_address'];
$store_email = $store_info['config_email'];
$store_telephone = $store_info['config_telephone'];
$store_fax = $store_info['config_fax'];
} else {
$store_address = $this->config->get('config_address');
$store_email = $this->config->get('config_email');
$store_telephone = $this->config->get('config_telephone');
$store_fax = $this->config->get('config_fax');
}
if ($order_info['invoice_no']) {
$invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$invoice_no = '';
}
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$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))));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$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))));
$product_data = array();
$products = $this->model_sale_order->getOrderProducts($order_id);
foreach ($products as $product) {
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
}
$option_data[] = array(
'name' => $option['name'],
'value' => $value
);
}
$product_data[] = array(
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
);
}
$voucher_data = array();
$vouchers = $this->model_sale_order->getOrderVouchers($order_id);
foreach ($vouchers as $voucher) {
$voucher_data[] = array(
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
);
}
$total_data = array();
$totals = $this->model_sale_order->getOrderTotals($order_id);
foreach ($totals as $total) {
$total_data[] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
);
}
$data['orders'][] = array(
'order_id' => $order_id,
'invoice_no' => $invoice_no,
'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
'store_name' => $order_info['store_name'],
'store_url' => rtrim($order_info['store_url'], '/'),
'store_address' => nl2br($store_address),
'store_email' => $store_email,
'store_telephone' => $store_telephone,
'store_fax' => $store_fax,
'email' => $order_info['email'],
'telephone' => $order_info['telephone'],
'shipping_address' => $shipping_address,
'shipping_method' => $order_info['shipping_method'],
'payment_address' => $payment_address,
'payment_method' => $order_info['payment_method'],
'product' => $product_data,
'voucher' => $voucher_data,
'total' => $total_data,
'comment' => nl2br($order_info['comment'])
);
}
}
$this->response->setOutput($this->load->view('sale/order_invoice.tpl', $data));
}
public function shipping() {
$this->load->language('sale/order');
$data['title'] = $this->language->get('text_shipping');
if ($this->request->server['HTTPS']) {
$data['base'] = HTTPS_SERVER;
} else {
$data['base'] = HTTP_SERVER;
}
$data['direction'] = $this->language->get('direction');
$data['lang'] = $this->language->get('code');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_order_detail'] = $this->language->get('text_order_detail');
$data['text_order_id'] = $this->language->get('text_order_id');
$data['text_invoice_no'] = $this->language->get('text_invoice_no');
$data['text_invoice_date'] = $this->language->get('text_invoice_date');
$data['text_date_added'] = $this->language->get('text_date_added');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_email'] = $this->language->get('text_email');
$data['text_website'] = $this->language->get('text_website');
$data['text_contact'] = $this->language->get('text_contact');
$data['text_from'] = $this->language->get('text_from');
$data['text_to'] = $this->language->get('text_to');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['text_sku'] = $this->language->get('text_sku');
$data['text_upc'] = $this->language->get('text_upc');
$data['text_ean'] = $this->language->get('text_ean');
$data['text_jan'] = $this->language->get('text_jan');
$data['text_isbn'] = $this->language->get('text_isbn');
$data['text_mpn'] = $this->language->get('text_mpn');
$data['column_location'] = $this->language->get('column_location');
$data['column_reference'] = $this->language->get('column_reference');
$data['column_product'] = $this->language->get('column_product');
$data['column_model'] = $this->language->get('column_model');
$data['column_quantity'] = $this->language->get('column_quantity');
$data['column_comment'] = $this->language->get('column_comment');
$this->load->model('sale/order');
$this->load->model('catalog/product');
$this->load->model('setting/setting');
$data['orders'] = array();
$orders = array();
if (isset($this->request->post['selected'])) {
$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
$orders[] = $this->request->get['order_id'];
}
foreach ($orders as $order_id) {
$order_info = $this->model_sale_order->getOrder($order_id);
// Make sure there is a shipping method
if ($order_info && $order_info['shipping_method']) {
$store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
if ($store_info) {
$store_address = $store_info['config_address'];
$store_email = $store_info['config_email'];
$store_telephone = $store_info['config_telephone'];
$store_fax = $store_info['config_fax'];
} else {
$store_address = $this->config->get('config_address');
$store_email = $this->config->get('config_email');
$store_telephone = $this->config->get('config_telephone');
$store_fax = $this->config->get('config_fax');
}
if ($order_info['invoice_no']) {
$invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$invoice_no = '';
}
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$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))));
$product_data = array();
$products = $this->model_sale_order->getOrderProducts($order_id);
foreach ($products as $product) {
$product_info = $this->model_catalog_product->getProduct($product['product_id']);
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
}
$option_data[] = array(
'name' => $option['name'],
'value' => $value
);
}
$product_data[] = array(
'name' => $product_info['name'],
'model' => $product_info['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'location' => $product_info['location'],
'sku' => $product_info['sku'],
'upc' => $product_info['upc'],
'ean' => $product_info['ean'],
'jan' => $product_info['jan'],
'isbn' => $product_info['isbn'],
'mpn' => $product_info['mpn']
);
}
$data['orders'][] = array(
'order_id' => $order_id,
'invoice_no' => $invoice_no,
'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
'store_name' => $order_info['store_name'],
'store_url' => rtrim($order_info['store_url'], '/'),
'store_address' => nl2br($store_address),
'store_email' => $store_email,
'store_telephone' => $store_telephone,
'store_fax' => $store_fax,
'email' => $order_info['email'],
'telephone' => $order_info['telephone'],
'shipping_address' => $shipping_address,
'shipping_method' => $order_info['shipping_method'],
'product' => $product_data,
'comment' => nl2br($order_info['comment'])
);
}
}
$this->response->setOutput($this->load->view('sale/order_shipping.tpl', $data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment