$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['text_yes'] = $this->language->get('text_yes');
$this->data['text_no'] = $this->language->get('text_no');
$this->data['text_percent'] = $this->language->get('text_percent');
$this->data['text_amount'] = $this->language->get('text_amount');
$this->data['entry_name'] = $this->language->get('entry_name');
$this->data['entry_description'] = $this->language->get('entry_description');
$this->data['entry_code'] = $this->language->get('entry_code');
$this->data['entry_discount'] = $this->language->get('entry_discount');
$this->data['entry_logged'] = $this->language->get('entry_logged');
$this->data['entry_shipping'] = $this->language->get('entry_shipping');
$this->data['entry_type'] = $this->language->get('entry_type');
$this->data['entry_total'] = $this->language->get('entry_total');
$this->data['entry_category'] = $this->language->get('entry_category');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_date_start'] = $this->language->get('entry_date_start');
$this->data['entry_date_end'] = $this->language->get('entry_date_end');
$this->data['entry_uses_total'] = $this->language->get('entry_uses_total');
$this->data['entry_uses_customer'] = $this->language->get('entry_uses_customer');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['tab_history'] = $this->language->get('tab_history');
$this->data['token'] = $this->session->data['token'];
if (isset($this->request->get['coupon_id'])) {
$this->data['coupon_id'] = $this->request->get['coupon_id'];
} else {
$this->data['coupon_id'] = 0;
}
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->error['name'])) {
$this->data['error_name'] = $this->error['name'];
} else {
$this->data['error_name'] = '';
}
if (isset($this->error['code'])) {
$this->data['error_code'] = $this->error['code'];
} else {
$this->data['error_code'] = '';
}
if (isset($this->error['date_start'])) {
$this->data['error_date_start'] = $this->error['date_start'];
} else {
$this->data['error_date_start'] = '';
}
if (isset($this->error['date_end'])) {
$this->data['error_date_end'] = $this->error['date_end'];
} else {
$this->data['error_date_end'] = '';
}
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('sale/coupon', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['coupon_id'])) {
$this->data['action'] = $this->url->link('sale/coupon/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
} else {
$this->data['action'] = $this->url->link('sale/coupon/update', 'token=' . $this->session->data['token'] . '&coupon_id=' . $this->request->get['coupon_id'] . $url, 'SSL');
}
$this->data['cancel'] = $this->url->link('sale/coupon', 'token=' . $this->session->data['token'] . $url, 'SSL');
if (isset($this->request->get['coupon_id']) && (!$this->request->server['REQUEST_METHOD'] != 'POST')) {
$coupon_info = $this->model_sale_coupon->getCoupon($this->request->get['coupon_id']);
}
if (isset($this->request->post['name'])) {
$this->data['name'] = $this->request->post['name'];
} elseif (!empty($coupon_info)) {
$this->data['name'] = $coupon_info['name'];
} else {
$this->data['name'] = '';
}
if (isset($this->request->post['code'])) {
$this->data['code'] = $this->request->post['code'];
} elseif (!empty($coupon_info)) {
$this->data['code'] = $coupon_info['code'];
} else {
$this->data['code'] = '';
}
if (isset($this->request->post['type'])) {
$this->data['type'] = $this->request->post['type'];
} elseif (!empty($coupon_info)) {
$this->data['type'] = $coupon_info['type'];
} else {
$this->data['type'] = '';
}
if (isset($this->request->post['discount'])) {
$this->data['discount'] = $this->request->post['discount'];
} elseif (!empty($coupon_info)) {
$this->data['discount'] = $coupon_info['discount'];
} else {
$this->data['discount'] = '';
}
if (isset($this->request->post['logged'])) {
$this->data['logged'] = $this->request->post['logged'];
} elseif (!empty($coupon_info)) {
$this->data['logged'] = $coupon_info['logged'];
} else {
$this->data['logged'] = '';
}
if (isset($this->request->post['shipping'])) {
$this->data['shipping'] = $this->request->post['shipping'];
} elseif (!empty($coupon_info)) {
$this->data['shipping'] = $coupon_info['shipping'];
} else {
$this->data['shipping'] = '';
}
if (isset($this->request->post['total'])) {
$this->data['total'] = $this->request->post['total'];
} elseif (!empty($coupon_info)) {
$this->data['total'] = $coupon_info['total'];
} else {
$this->data['total'] = '';
}
if (isset($this->request->post['coupon_product'])) {
$products = $this->request->post['coupon_product'];
} elseif (isset($this->request->get['coupon_id'])) {
$products = $this->model_sale_coupon->getCouponProducts($this->request->get['coupon_id']);
} else {
$products = array();
}
$this->load->model('catalog/product');
$this->data['coupon_product'] = array();
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$this->data['coupon_product'][] = array(
'product_id' => $product_info['product_id'],
'name' => $product_info['name']
);
}
}
if (isset($this->request->post['coupon_category'])) {
$categories = $this->request->post['coupon_category'];
} elseif (isset($this->request->get['coupon_id'])) {
$categories = $this->model_sale_coupon->getCouponCategories($this->request->get['coupon_id']);
} else {
$categories = array();
}
$this->load->model('catalog/category');
$this->data['coupon_category'] = array();
foreach ($categories as $category_id) {
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$this->data['coupon_category'][] = array(
'category_id' => $category_info['category_id'],
'name' => ($category_info['path'] ? $category_info['path'] . ' > ' : '') . $category_info['name']
);
}
}
if (isset($this->request->post['date_start'])) {
$this->data['date_start'] = $this->request->post['date_start'];
} elseif (!empty($coupon_info)) {
$this->data['date_start'] = date('Y-m-d', strtotime($coupon_info['date_start']));
} else {
$this->data['date_start'] = date('Y-m-d', time());
}
if (isset($this->request->post['date_end'])) {
$this->data['date_end'] = $this->request->post['date_end'];
} elseif (!empty($coupon_info)) {
$this->data['date_end'] = date('Y-m-d', strtotime($coupon_info['date_end']));
} else {
$this->data['date_end'] = date('Y-m-d', time());
}
if (isset($this->request->post['uses_total'])) {
$this->data['uses_total'] = $this->request->post['uses_total'];
} elseif (!empty($coupon_info)) {
$this->data['uses_total'] = $coupon_info['uses_total'];
} else {
$this->data['uses_total'] = 1;
}
if (isset($this->request->post['uses_customer'])) {
$this->data['uses_customer'] = $this->request->post['uses_customer'];
} elseif (!empty($coupon_info)) {
$this->data['uses_customer'] = $coupon_info['uses_customer'];
} else {
$this->data['uses_customer'] = 1;
}
if (isset($this->request->post['status'])) {
$this->data['status'] = $this->request->post['status'];
} elseif (!empty($coupon_info)) {
$this->data['status'] = $coupon_info['status'];
} else {
$this->data['status'] = 1;
}
$this->template = 'sale/coupon_form.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());