diff options
Diffstat (limited to 'public/admin/controller')
252 files changed, 78041 insertions, 0 deletions
diff --git a/public/admin/controller/catalog/attribute.php b/public/admin/controller/catalog/attribute.php new file mode 100644 index 0000000..d3cebea --- /dev/null +++ b/public/admin/controller/catalog/attribute.php @@ -0,0 +1,418 @@ +<?php +class ControllerCatalogAttribute extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/attribute'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/attribute'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_attribute->addAttribute($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/attribute'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_attribute->editAttribute($this->request->get['attribute_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/attribute'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $attribute_id) { + $this->model_catalog_attribute->deleteAttribute($attribute_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'ad.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/attribute/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/attribute/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['attributes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $attribute_total = $this->model_catalog_attribute->getTotalAttributes(); + + $results = $this->model_catalog_attribute->getAttributes($filter_data); + + foreach ($results as $result) { + $data['attributes'][] = array( + 'attribute_id' => $result['attribute_id'], + 'name' => $result['name'], + 'attribute_group' => $result['attribute_group'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/attribute/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_id=' . $result['attribute_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=ad.name' . $url, true); + $data['sort_attribute_group'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=attribute_group' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=a.sort_order' . $url, true); + + $url = ''; + + 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 = $attribute_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($attribute_total - $this->config->get('config_limit_admin'))) ? $attribute_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $attribute_total, ceil($attribute_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/attribute_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['attribute_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['attribute_group'])) { + $data['error_attribute_group'] = $this->error['attribute_group']; + } else { + $data['error_attribute_group'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['attribute_id'])) { + $data['action'] = $this->url->link('catalog/attribute/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/attribute/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_id=' . $this->request->get['attribute_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['attribute_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $attribute_info = $this->model_catalog_attribute->getAttribute($this->request->get['attribute_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['attribute_description'])) { + $data['attribute_description'] = $this->request->post['attribute_description']; + } elseif (isset($this->request->get['attribute_id'])) { + $data['attribute_description'] = $this->model_catalog_attribute->getAttributeDescriptions($this->request->get['attribute_id']); + } else { + $data['attribute_description'] = array(); + } + + if (isset($this->request->post['attribute_group_id'])) { + $data['attribute_group_id'] = $this->request->post['attribute_group_id']; + } elseif (!empty($attribute_info)) { + $data['attribute_group_id'] = $attribute_info['attribute_group_id']; + } else { + $data['attribute_group_id'] = ''; + } + + $this->load->model('catalog/attribute_group'); + + $data['attribute_groups'] = $this->model_catalog_attribute_group->getAttributeGroups(); + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($attribute_info)) { + $data['sort_order'] = $attribute_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/attribute_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/attribute')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['attribute_group_id']) { + $this->error['attribute_group'] = $this->language->get('error_attribute_group'); + } + + foreach ($this->request->post['attribute_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/attribute')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $attribute_id) { + $product_total = $this->model_catalog_product->getTotalProductsByAttributeId($attribute_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('catalog/attribute'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_catalog_attribute->getAttributes($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'attribute_id' => $result['attribute_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), + 'attribute_group' => $result['attribute_group'] + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/catalog/attribute_group.php b/public/admin/controller/catalog/attribute_group.php new file mode 100644 index 0000000..0147758 --- /dev/null +++ b/public/admin/controller/catalog/attribute_group.php @@ -0,0 +1,359 @@ +<?php +class ControllerCatalogAttributeGroup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/attribute_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute_group'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/attribute_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_attribute_group->addAttributeGroup($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/attribute_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_attribute_group->editAttributeGroup($this->request->get['attribute_group_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/attribute_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/attribute_group'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $attribute_group_id) { + $this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'agd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/attribute_group/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['attribute_groups'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups(); + + $results = $this->model_catalog_attribute_group->getAttributeGroups($filter_data); + + foreach ($results as $result) { + $data['attribute_groups'][] = array( + 'attribute_group_id' => $result['attribute_group_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $result['attribute_group_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=agd.name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=ag.sort_order' . $url, true); + + $url = ''; + + 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 = $attribute_group_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_group_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($attribute_group_total - $this->config->get('config_limit_admin'))) ? $attribute_group_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $attribute_group_total, ceil($attribute_group_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/attribute_group_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['attribute_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['attribute_group_id'])) { + $data['action'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $this->request->get['attribute_group_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['attribute_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($this->request->get['attribute_group_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['attribute_group_description'])) { + $data['attribute_group_description'] = $this->request->post['attribute_group_description']; + } elseif (isset($this->request->get['attribute_group_id'])) { + $data['attribute_group_description'] = $this->model_catalog_attribute_group->getAttributeGroupDescriptions($this->request->get['attribute_group_id']); + } else { + $data['attribute_group_description'] = array(); + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($attribute_group_info)) { + $data['sort_order'] = $attribute_group_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/attribute_group_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['attribute_group_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/attribute'); + + foreach ($this->request->post['selected'] as $attribute_group_id) { + $attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($attribute_group_id); + + if ($attribute_total) { + $this->error['warning'] = sprintf($this->language->get('error_attribute'), $attribute_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/catalog/category.php b/public/admin/controller/catalog/category.php new file mode 100644 index 0000000..958879c --- /dev/null +++ b/public/admin/controller/catalog/category.php @@ -0,0 +1,620 @@ +<?php +class ControllerCatalogCategory extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/category'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/category'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_category->addCategory($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/category'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_category->editCategory($this->request->get['category_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/category'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $category_id) { + $this->model_catalog_category->deleteCategory($category_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function repair() { + $this->load->language('catalog/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/category'); + + if ($this->validateRepair()) { + $this->model_catalog_category->repairCategories(); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/category/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/category/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['repair'] = $this->url->link('catalog/category/repair', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['categories'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $category_total = $this->model_catalog_category->getTotalCategories(); + + $results = $this->model_catalog_category->getCategories($filter_data); + + foreach ($results as $result) { + $data['categories'][] = array( + 'category_id' => $result['category_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/category/edit', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $result['category_id'] . $url, true), + 'delete' => $this->url->link('catalog/category/delete', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $result['category_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true); + + $url = ''; + + 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 = $category_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($category_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($category_total - $this->config->get('config_limit_admin'))) ? $category_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $category_total, ceil($category_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/category_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['meta_title'])) { + $data['error_meta_title'] = $this->error['meta_title']; + } else { + $data['error_meta_title'] = array(); + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + if (isset($this->error['parent'])) { + $data['error_parent'] = $this->error['parent']; + } else { + $data['error_parent'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['category_id'])) { + $data['action'] = $this->url->link('catalog/category/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/category/edit', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $this->request->get['category_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['category_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $category_info = $this->model_catalog_category->getCategory($this->request->get['category_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['category_description'])) { + $data['category_description'] = $this->request->post['category_description']; + } elseif (isset($this->request->get['category_id'])) { + $data['category_description'] = $this->model_catalog_category->getCategoryDescriptions($this->request->get['category_id']); + } else { + $data['category_description'] = array(); + } + + if (isset($this->request->post['path'])) { + $data['path'] = $this->request->post['path']; + } elseif (!empty($category_info)) { + $data['path'] = $category_info['path']; + } else { + $data['path'] = ''; + } + + if (isset($this->request->post['parent_id'])) { + $data['parent_id'] = $this->request->post['parent_id']; + } elseif (!empty($category_info)) { + $data['parent_id'] = $category_info['parent_id']; + } else { + $data['parent_id'] = 0; + } + + $this->load->model('catalog/filter'); + + if (isset($this->request->post['category_filter'])) { + $filters = $this->request->post['category_filter']; + } elseif (isset($this->request->get['category_id'])) { + $filters = $this->model_catalog_category->getCategoryFilters($this->request->get['category_id']); + } else { + $filters = array(); + } + + $data['category_filters'] = array(); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['category_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'name' => $filter_info['group'] . ' > ' . $filter_info['name'] + ); + } + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['category_store'])) { + $data['category_store'] = $this->request->post['category_store']; + } elseif (isset($this->request->get['category_id'])) { + $data['category_store'] = $this->model_catalog_category->getCategoryStores($this->request->get['category_id']); + } else { + $data['category_store'] = array(0); + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($category_info)) { + $data['image'] = $category_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($category_info) && is_file(DIR_IMAGE . $category_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($category_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['top'])) { + $data['top'] = $this->request->post['top']; + } elseif (!empty($category_info)) { + $data['top'] = $category_info['top']; + } else { + $data['top'] = 0; + } + + if (isset($this->request->post['column'])) { + $data['column'] = $this->request->post['column']; + } elseif (!empty($category_info)) { + $data['column'] = $category_info['column']; + } else { + $data['column'] = 1; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($category_info)) { + $data['sort_order'] = $category_info['sort_order']; + } else { + $data['sort_order'] = 0; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($category_info)) { + $data['status'] = $category_info['status']; + } else { + $data['status'] = true; + } + + if (isset($this->request->post['category_seo_url'])) { + $data['category_seo_url'] = $this->request->post['category_seo_url']; + } elseif (isset($this->request->get['category_id'])) { + $data['category_seo_url'] = $this->model_catalog_category->getCategorySeoUrls($this->request->get['category_id']); + } else { + $data['category_seo_url'] = array(); + } + + if (isset($this->request->post['category_layout'])) { + $data['category_layout'] = $this->request->post['category_layout']; + } elseif (isset($this->request->get['category_id'])) { + $data['category_layout'] = $this->model_catalog_category->getCategoryLayouts($this->request->get['category_id']); + } else { + $data['category_layout'] = array(); + } + + $this->load->model('design/layout'); + + $data['layouts'] = $this->model_design_layout->getLayouts(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/category_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/category')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['category_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 255)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + + if ((utf8_strlen($value['meta_title']) < 1) || (utf8_strlen($value['meta_title']) > 255)) { + $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title'); + } + } + + if (isset($this->request->get['category_id']) && $this->request->post['parent_id']) { + $results = $this->model_catalog_category->getCategoryPath($this->request->post['parent_id']); + + foreach ($results as $result) { + if ($result['path_id'] == $this->request->get['category_id']) { + $this->error['parent'] = $this->language->get('error_parent'); + + break; + } + } + } + + if ($this->request->post['category_seo_url']) { + $this->load->model('design/seo_url'); + + foreach ($this->request->post['category_seo_url'] as $store_id => $language) { + foreach ($language as $language_id => $keyword) { + if (!empty($keyword)) { + if (count(array_keys($language, $keyword)) > 1) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword); + + foreach ($seo_urls as $seo_url) { + if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['category_id']) || ($seo_url['query'] != 'category_id=' . $this->request->get['category_id']))) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword'); + + break; + } + } + } + } + } + } + + 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', 'catalog/category')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + protected function validateRepair() { + if (!$this->user->hasPermission('modify', 'catalog/category')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('catalog/category'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'sort' => 'name', + 'order' => 'ASC', + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_catalog_category->getCategories($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'category_id' => $result['category_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/catalog/download.php b/public/admin/controller/catalog/download.php new file mode 100644 index 0000000..3b9f5c4 --- /dev/null +++ b/public/admin/controller/catalog/download.php @@ -0,0 +1,514 @@ +<?php +class ControllerCatalogDownload extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/download'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/download'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/download'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/download'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_download->addDownload($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/download'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/download'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_download->editDownload($this->request->get['download_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/download'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/download'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $download_id) { + $this->model_catalog_download->deleteDownload($download_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'dd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/download/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/download/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['downloads'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $download_total = $this->model_catalog_download->getTotalDownloads(); + + $results = $this->model_catalog_download->getDownloads($filter_data); + + foreach ($results as $result) { + $data['downloads'][] = array( + 'download_id' => $result['download_id'], + 'name' => $result['name'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('catalog/download/edit', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $result['download_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . '&sort=dd.name' . $url, true); + $data['sort_date_added'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . '&sort=d.date_added' . $url, true); + + $url = ''; + + 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 = $download_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($download_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($download_total - $this->config->get('config_limit_admin'))) ? $download_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $download_total, ceil($download_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/download_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['download_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['filename'])) { + $data['error_filename'] = $this->error['filename']; + } else { + $data['error_filename'] = ''; + } + + if (isset($this->error['mask'])) { + $data['error_mask'] = $this->error['mask']; + } else { + $data['error_mask'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['download_id'])) { + $data['action'] = $this->url->link('catalog/download/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/download/edit', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $this->request->get['download_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->get['download_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['download_id'])) { + $data['download_id'] = $this->request->get['download_id']; + } else { + $data['download_id'] = 0; + } + + if (isset($this->request->post['download_description'])) { + $data['download_description'] = $this->request->post['download_description']; + } elseif (isset($this->request->get['download_id'])) { + $data['download_description'] = $this->model_catalog_download->getDownloadDescriptions($this->request->get['download_id']); + } else { + $data['download_description'] = array(); + } + + if (isset($this->request->post['filename'])) { + $data['filename'] = $this->request->post['filename']; + } elseif (!empty($download_info)) { + $data['filename'] = $download_info['filename']; + } else { + $data['filename'] = ''; + } + + if (isset($this->request->post['mask'])) { + $data['mask'] = $this->request->post['mask']; + } elseif (!empty($download_info)) { + $data['mask'] = $download_info['mask']; + } else { + $data['mask'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/download_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/download')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['download_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 64)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + if ((utf8_strlen($this->request->post['filename']) < 3) || (utf8_strlen($this->request->post['filename']) > 128)) { + $this->error['filename'] = $this->language->get('error_filename'); + } + + if (!is_file(DIR_DOWNLOAD . $this->request->post['filename'])) { + $this->error['filename'] = $this->language->get('error_exists'); + } + + if ((utf8_strlen($this->request->post['mask']) < 3) || (utf8_strlen($this->request->post['mask']) > 128)) { + $this->error['mask'] = $this->language->get('error_mask'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/download')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $download_id) { + $product_total = $this->model_catalog_product->getTotalProductsByDownloadId($download_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } + + public function upload() { + $this->load->language('catalog/download'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'catalog/download')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_name'])) { + // Sanitize the filename + $filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')); + + // Validate the filename length + 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_ext_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'); + } + + // Check to see if any PHP files are trying to be uploaded + $content = file_get_contents($this->request->files['file']['tmp_name']); + + if (preg_match('/\<\?php/i', $content)) { + $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 . '.' . token(32); + + move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file); + + $json['filename'] = $file; + $json['mask'] = $filename; + + $json['success'] = $this->language->get('text_upload'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('catalog/download'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_catalog_download->getDownloads($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'download_id' => $result['download_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/filter.php b/public/admin/controller/catalog/filter.php new file mode 100644 index 0000000..91902a2 --- /dev/null +++ b/public/admin/controller/catalog/filter.php @@ -0,0 +1,409 @@ +<?php +class ControllerCatalogFilter extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/filter'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/filter'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_filter->addFilter($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/filter'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_filter->editFilter($this->request->get['filter_group_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/filter'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $filter_group_id) { + $this->model_catalog_filter->deleteFilter($filter_group_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'fgd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/filter/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/filter/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['filters'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $filter_total = $this->model_catalog_filter->getTotalFilterGroups(); + + $results = $this->model_catalog_filter->getFilterGroups($filter_data); + + foreach ($results as $result) { + $data['filters'][] = array( + 'filter_group_id' => $result['filter_group_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/filter/edit', 'user_token=' . $this->session->data['user_token'] . '&filter_group_id=' . $result['filter_group_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . '&sort=fgd.name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . '&sort=fg.sort_order' . $url, true); + + $url = ''; + + 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 = $filter_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($filter_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($filter_total - $this->config->get('config_limit_admin'))) ? $filter_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $filter_total, ceil($filter_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/filter_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['filter_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['group'])) { + $data['error_group'] = $this->error['group']; + } else { + $data['error_group'] = array(); + } + + if (isset($this->error['filter'])) { + $data['error_filter'] = $this->error['filter']; + } else { + $data['error_filter'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['filter_group_id'])) { + $data['action'] = $this->url->link('catalog/filter/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/filter/edit', 'user_token=' . $this->session->data['user_token'] . '&filter_group_id=' . $this->request->get['filter_group_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['filter_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $filter_group_info = $this->model_catalog_filter->getFilterGroup($this->request->get['filter_group_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['filter_group_description'])) { + $data['filter_group_description'] = $this->request->post['filter_group_description']; + } elseif (isset($this->request->get['filter_group_id'])) { + $data['filter_group_description'] = $this->model_catalog_filter->getFilterGroupDescriptions($this->request->get['filter_group_id']); + } else { + $data['filter_group_description'] = array(); + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($filter_group_info)) { + $data['sort_order'] = $filter_group_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + if (isset($this->request->post['filter'])) { + $data['filters'] = $this->request->post['filter']; + } elseif (isset($this->request->get['filter_group_id'])) { + $data['filters'] = $this->model_catalog_filter->getFilterDescriptions($this->request->get['filter_group_id']); + } else { + $data['filters'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/filter_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/filter')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['filter_group_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) { + $this->error['group'][$language_id] = $this->language->get('error_group'); + } + } + + if (isset($this->request->post['filter'])) { + foreach ($this->request->post['filter'] as $filter_id => $filter) { + foreach ($filter['filter_description'] as $language_id => $filter_description) { + if ((utf8_strlen($filter_description['name']) < 1) || (utf8_strlen($filter_description['name']) > 64)) { + $this->error['filter'][$filter_id][$language_id] = $this->language->get('error_name'); + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/filter')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('catalog/filter'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'start' => 0, + 'limit' => 5 + ); + + $filters = $this->model_catalog_filter->getFilters($filter_data); + + foreach ($filters as $filter) { + $json[] = array( + 'filter_id' => $filter['filter_id'], + 'name' => strip_tags(html_entity_decode($filter['group'] . ' > ' . $filter['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/information.php b/public/admin/controller/catalog/information.php new file mode 100644 index 0000000..244913d --- /dev/null +++ b/public/admin/controller/catalog/information.php @@ -0,0 +1,491 @@ +<?php +class ControllerCatalogInformation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/information'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/information'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_information->addInformation($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/information'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_information->editInformation($this->request->get['information_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/information'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $information_id) { + $this->model_catalog_information->deleteInformation($information_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'id.title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/information/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['informations'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $information_total = $this->model_catalog_information->getTotalInformations(); + + $results = $this->model_catalog_information->getInformations($filter_data); + + foreach ($results as $result) { + $data['informations'][] = array( + 'information_id' => $result['information_id'], + 'title' => $result['title'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $result['information_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=id.title' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=i.sort_order' . $url, true); + + $url = ''; + + 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 = $information_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($information_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($information_total - $this->config->get('config_limit_admin'))) ? $information_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $information_total, ceil($information_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/information_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['information_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = array(); + } + + if (isset($this->error['description'])) { + $data['error_description'] = $this->error['description']; + } else { + $data['error_description'] = array(); + } + + if (isset($this->error['meta_title'])) { + $data['error_meta_title'] = $this->error['meta_title']; + } else { + $data['error_meta_title'] = array(); + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['information_id'])) { + $data['action'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $this->request->get['information_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['information_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $information_info = $this->model_catalog_information->getInformation($this->request->get['information_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['information_description'])) { + $data['information_description'] = $this->request->post['information_description']; + } elseif (isset($this->request->get['information_id'])) { + $data['information_description'] = $this->model_catalog_information->getInformationDescriptions($this->request->get['information_id']); + } else { + $data['information_description'] = array(); + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['information_store'])) { + $data['information_store'] = $this->request->post['information_store']; + } elseif (isset($this->request->get['information_id'])) { + $data['information_store'] = $this->model_catalog_information->getInformationStores($this->request->get['information_id']); + } else { + $data['information_store'] = array(0); + } + + if (isset($this->request->post['bottom'])) { + $data['bottom'] = $this->request->post['bottom']; + } elseif (!empty($information_info)) { + $data['bottom'] = $information_info['bottom']; + } else { + $data['bottom'] = 0; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($information_info)) { + $data['status'] = $information_info['status']; + } else { + $data['status'] = true; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($information_info)) { + $data['sort_order'] = $information_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + if (isset($this->request->post['information_seo_url'])) { + $data['information_seo_url'] = $this->request->post['information_seo_url']; + } elseif (isset($this->request->get['information_id'])) { + $data['information_seo_url'] = $this->model_catalog_information->getInformationSeoUrls($this->request->get['information_id']); + } else { + $data['information_seo_url'] = array(); + } + + if (isset($this->request->post['information_layout'])) { + $data['information_layout'] = $this->request->post['information_layout']; + } elseif (isset($this->request->get['information_id'])) { + $data['information_layout'] = $this->model_catalog_information->getInformationLayouts($this->request->get['information_id']); + } else { + $data['information_layout'] = array(); + } + + $this->load->model('design/layout'); + + $data['layouts'] = $this->model_design_layout->getLayouts(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/information_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/information')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['information_description'] as $language_id => $value) { + if ((utf8_strlen($value['title']) < 1) || (utf8_strlen($value['title']) > 64)) { + $this->error['title'][$language_id] = $this->language->get('error_title'); + } + + if (utf8_strlen($value['description']) < 3) { + $this->error['description'][$language_id] = $this->language->get('error_description'); + } + + if ((utf8_strlen($value['meta_title']) < 1) || (utf8_strlen($value['meta_title']) > 255)) { + $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title'); + } + } + + if ($this->request->post['information_seo_url']) { + $this->load->model('design/seo_url'); + + foreach ($this->request->post['information_seo_url'] as $store_id => $language) { + foreach ($language as $language_id => $keyword) { + if (!empty($keyword)) { + if (count(array_keys($language, $keyword)) > 1) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword); + + foreach ($seo_urls as $seo_url) { + if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['information_id']) || ($seo_url['query'] != 'information_id=' . $this->request->get['information_id']))) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword'); + } + } + } + } + } + } + + 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', 'catalog/information')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + + foreach ($this->request->post['selected'] as $information_id) { + if ($this->config->get('config_account_id') == $information_id) { + $this->error['warning'] = $this->language->get('error_account'); + } + + if ($this->config->get('config_checkout_id') == $information_id) { + $this->error['warning'] = $this->language->get('error_checkout'); + } + + if ($this->config->get('config_affiliate_id') == $information_id) { + $this->error['warning'] = $this->language->get('error_affiliate'); + } + + if ($this->config->get('config_return_id') == $information_id) { + $this->error['warning'] = $this->language->get('error_return'); + } + + $store_total = $this->model_setting_store->getTotalStoresByInformationId($information_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/manufacturer.php b/public/admin/controller/catalog/manufacturer.php new file mode 100644 index 0000000..c0cc5de --- /dev/null +++ b/public/admin/controller/catalog/manufacturer.php @@ -0,0 +1,475 @@ +<?php +class ControllerCatalogManufacturer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/manufacturer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/manufacturer'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/manufacturer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/manufacturer'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_manufacturer->addManufacturer($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/manufacturer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/manufacturer'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_manufacturer->editManufacturer($this->request->get['manufacturer_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/manufacturer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/manufacturer'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $manufacturer_id) { + $this->model_catalog_manufacturer->deleteManufacturer($manufacturer_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/manufacturer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/manufacturer/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['manufacturers'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturers(); + + $results = $this->model_catalog_manufacturer->getManufacturers($filter_data); + + foreach ($results as $result) { + $data['manufacturers'][] = array( + 'manufacturer_id' => $result['manufacturer_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/manufacturer/edit', 'user_token=' . $this->session->data['user_token'] . '&manufacturer_id=' . $result['manufacturer_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true); + + $url = ''; + + 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 = $manufacturer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($manufacturer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($manufacturer_total - $this->config->get('config_limit_admin'))) ? $manufacturer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $manufacturer_total, ceil($manufacturer_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/manufacturer_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['manufacturer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['manufacturer_id'])) { + $data['action'] = $this->url->link('catalog/manufacturer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/manufacturer/edit', 'user_token=' . $this->session->data['user_token'] . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['manufacturer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($manufacturer_info)) { + $data['name'] = $manufacturer_info['name']; + } else { + $data['name'] = ''; + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['manufacturer_store'])) { + $data['manufacturer_store'] = $this->request->post['manufacturer_store']; + } elseif (isset($this->request->get['manufacturer_id'])) { + $data['manufacturer_store'] = $this->model_catalog_manufacturer->getManufacturerStores($this->request->get['manufacturer_id']); + } else { + $data['manufacturer_store'] = array(0); + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($manufacturer_info)) { + $data['image'] = $manufacturer_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($manufacturer_info) && is_file(DIR_IMAGE . $manufacturer_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($manufacturer_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($manufacturer_info)) { + $data['sort_order'] = $manufacturer_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['manufacturer_seo_url'])) { + $data['manufacturer_seo_url'] = $this->request->post['manufacturer_seo_url']; + } elseif (isset($this->request->get['manufacturer_id'])) { + $data['manufacturer_seo_url'] = $this->model_catalog_manufacturer->getManufacturerSeoUrls($this->request->get['manufacturer_id']); + } else { + $data['manufacturer_seo_url'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/manufacturer_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ($this->request->post['manufacturer_seo_url']) { + $this->load->model('design/seo_url'); + + foreach ($this->request->post['manufacturer_seo_url'] as $store_id => $language) { + foreach ($language as $language_id => $keyword) { + if (!empty($keyword)) { + if (count(array_keys($language, $keyword)) > 1) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword); + + foreach ($seo_urls as $seo_url) { + if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['manufacturer_id']) || (($seo_url['query'] != 'manufacturer_id=' . $this->request->get['manufacturer_id'])))) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword'); + } + } + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $manufacturer_id) { + $product_total = $this->model_catalog_product->getTotalProductsByManufacturerId($manufacturer_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('catalog/manufacturer'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_catalog_manufacturer->getManufacturers($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'manufacturer_id' => $result['manufacturer_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/option.php b/public/admin/controller/catalog/option.php new file mode 100644 index 0000000..e92c1be --- /dev/null +++ b/public/admin/controller/catalog/option.php @@ -0,0 +1,508 @@ +<?php +class ControllerCatalogOption extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/option'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/option'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/option'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/option'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_option->addOption($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/option'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/option'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_option->editOption($this->request->get['option_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/option'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/option'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $option_id) { + $this->model_catalog_option->deleteOption($option_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'od.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/option/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/option/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['options'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $option_total = $this->model_catalog_option->getTotalOptions(); + + $results = $this->model_catalog_option->getOptions($filter_data); + + foreach ($results as $result) { + $data['options'][] = array( + 'option_id' => $result['option_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/option/edit', 'user_token=' . $this->session->data['user_token'] . '&option_id=' . $result['option_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . '&sort=od.name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . '&sort=o.sort_order' . $url, true); + + $url = ''; + + 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 = $option_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($option_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($option_total - $this->config->get('config_limit_admin'))) ? $option_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $option_total, ceil($option_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/option_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['option_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['option_value'])) { + $data['error_option_value'] = $this->error['option_value']; + } else { + $data['error_option_value'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['option_id'])) { + $data['action'] = $this->url->link('catalog/option/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/option/edit', 'user_token=' . $this->session->data['user_token'] . '&option_id=' . $this->request->get['option_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['option_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $option_info = $this->model_catalog_option->getOption($this->request->get['option_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['option_description'])) { + $data['option_description'] = $this->request->post['option_description']; + } elseif (isset($this->request->get['option_id'])) { + $data['option_description'] = $this->model_catalog_option->getOptionDescriptions($this->request->get['option_id']); + } else { + $data['option_description'] = array(); + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } elseif (!empty($option_info)) { + $data['type'] = $option_info['type']; + } else { + $data['type'] = ''; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($option_info)) { + $data['sort_order'] = $option_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + if (isset($this->request->post['option_value'])) { + $option_values = $this->request->post['option_value']; + } elseif (isset($this->request->get['option_id'])) { + $option_values = $this->model_catalog_option->getOptionValueDescriptions($this->request->get['option_id']); + } else { + $option_values = array(); + } + + $this->load->model('tool/image'); + + $data['option_values'] = array(); + + foreach ($option_values as $option_value) { + if (is_file(DIR_IMAGE . $option_value['image'])) { + $image = $option_value['image']; + $thumb = $option_value['image']; + } else { + $image = ''; + $thumb = 'no_image.png'; + } + + $data['option_values'][] = array( + 'option_value_id' => $option_value['option_value_id'], + 'option_value_description' => $option_value['option_value_description'], + 'image' => $image, + 'thumb' => $this->model_tool_image->resize($thumb, 100, 100), + 'sort_order' => $option_value['sort_order'] + ); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/option_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/option')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['option_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 128)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + if (($this->request->post['type'] == 'select' || $this->request->post['type'] == 'radio' || $this->request->post['type'] == 'checkbox') && !isset($this->request->post['option_value'])) { + $this->error['warning'] = $this->language->get('error_type'); + } + + if (isset($this->request->post['option_value'])) { + foreach ($this->request->post['option_value'] as $option_value_id => $option_value) { + foreach ($option_value['option_value_description'] as $language_id => $option_value_description) { + if ((utf8_strlen($option_value_description['name']) < 1) || (utf8_strlen($option_value_description['name']) > 128)) { + $this->error['option_value'][$option_value_id][$language_id] = $this->language->get('error_option_value'); + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/option')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $option_id) { + $product_total = $this->model_catalog_product->getTotalProductsByOptionId($option_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->language('catalog/option'); + + $this->load->model('catalog/option'); + + $this->load->model('tool/image'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'start' => 0, + 'limit' => 5 + ); + + $options = $this->model_catalog_option->getOptions($filter_data); + + foreach ($options as $option) { + $option_value_data = array(); + + if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') { + $option_values = $this->model_catalog_option->getOptionValues($option['option_id']); + + foreach ($option_values as $option_value) { + if (is_file(DIR_IMAGE . $option_value['image'])) { + $image = $this->model_tool_image->resize($option_value['image'], 50, 50); + } else { + $image = $this->model_tool_image->resize('no_image.png', 50, 50); + } + + $option_value_data[] = array( + 'option_value_id' => $option_value['option_value_id'], + 'name' => strip_tags(html_entity_decode($option_value['name'], ENT_QUOTES, 'UTF-8')), + 'image' => $image + ); + } + + $sort_order = array(); + + foreach ($option_value_data as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $option_value_data); + } + + $type = ''; + + if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox') { + $type = $this->language->get('text_choose'); + } + + if ($option['type'] == 'text' || $option['type'] == 'textarea') { + $type = $this->language->get('text_input'); + } + + if ($option['type'] == 'file') { + $type = $this->language->get('text_file'); + } + + if ($option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') { + $type = $this->language->get('text_date'); + } + + $json[] = array( + 'option_id' => $option['option_id'], + 'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')), + 'category' => $type, + 'type' => $option['type'], + 'option_value' => $option_value_data + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/product.php b/public/admin/controller/catalog/product.php new file mode 100644 index 0000000..d3bdb67 --- /dev/null +++ b/public/admin/controller/catalog/product.php @@ -0,0 +1,1324 @@ +<?php +class ControllerCatalogProduct extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/product'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/product'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/product'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/product'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_product->addProduct($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/product'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/product'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/product'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/product'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $product_id) { + $this->model_catalog_product->deleteProduct($product_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function copy() { + $this->load->language('catalog/product'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/product'); + + if (isset($this->request->post['selected']) && $this->validateCopy()) { + foreach ($this->request->post['selected'] as $product_id) { + $this->model_catalog_product->copyProduct($product_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_model'])) { + $filter_model = $this->request->get['filter_model']; + } else { + $filter_model = ''; + } + + if (isset($this->request->get['filter_price'])) { + $filter_price = $this->request->get['filter_price']; + } else { + $filter_price = ''; + } + + if (isset($this->request->get['filter_quantity'])) { + $filter_quantity = $this->request->get['filter_quantity']; + } else { + $filter_quantity = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'pd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/product/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['copy'] = $this->url->link('catalog/product/copy', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/product/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['products'] = array(); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_model' => $filter_model, + 'filter_price' => $filter_price, + 'filter_quantity' => $filter_quantity, + 'filter_status' => $filter_status, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $this->load->model('tool/image'); + + $product_total = $this->model_catalog_product->getTotalProducts($filter_data); + + $results = $this->model_catalog_product->getProducts($filter_data); + + foreach ($results as $result) { + if (is_file(DIR_IMAGE . $result['image'])) { + $image = $this->model_tool_image->resize($result['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + $special = false; + + $product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']); + + foreach ($product_specials as $product_special) { + if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) { + $special = $this->currency->format($product_special['price'], $this->config->get('config_currency')); + + break; + } + } + + $data['products'][] = array( + 'product_id' => $result['product_id'], + 'image' => $image, + 'name' => $result['name'], + 'model' => $result['model'], + 'price' => $this->currency->format($result['price'], $this->config->get('config_currency')), + 'special' => $special, + 'quantity' => $result['quantity'], + 'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'edit' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true); + $data['sort_model'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.model' . $url, true); + $data['sort_price'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.price' . $url, true); + $data['sort_quantity'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.quantity' . $url, true); + $data['sort_status'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.status' . $url, true); + $data['sort_order'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.sort_order' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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 = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + $data['filter_name'] = $filter_name; + $data['filter_model'] = $filter_model; + $data['filter_price'] = $filter_price; + $data['filter_quantity'] = $filter_quantity; + $data['filter_status'] = $filter_status; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/product_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['product_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['meta_title'])) { + $data['error_meta_title'] = $this->error['meta_title']; + } else { + $data['error_meta_title'] = array(); + } + + if (isset($this->error['model'])) { + $data['error_model'] = $this->error['model']; + } else { + $data['error_model'] = ''; + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['product_id'])) { + $data['action'] = $this->url->link('catalog/product/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['product_description'])) { + $data['product_description'] = $this->request->post['product_description']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']); + } else { + $data['product_description'] = array(); + } + + if (isset($this->request->post['model'])) { + $data['model'] = $this->request->post['model']; + } elseif (!empty($product_info)) { + $data['model'] = $product_info['model']; + } else { + $data['model'] = ''; + } + + if (isset($this->request->post['sku'])) { + $data['sku'] = $this->request->post['sku']; + } elseif (!empty($product_info)) { + $data['sku'] = $product_info['sku']; + } else { + $data['sku'] = ''; + } + + if (isset($this->request->post['upc'])) { + $data['upc'] = $this->request->post['upc']; + } elseif (!empty($product_info)) { + $data['upc'] = $product_info['upc']; + } else { + $data['upc'] = ''; + } + + if (isset($this->request->post['ean'])) { + $data['ean'] = $this->request->post['ean']; + } elseif (!empty($product_info)) { + $data['ean'] = $product_info['ean']; + } else { + $data['ean'] = ''; + } + + if (isset($this->request->post['jan'])) { + $data['jan'] = $this->request->post['jan']; + } elseif (!empty($product_info)) { + $data['jan'] = $product_info['jan']; + } else { + $data['jan'] = ''; + } + + if (isset($this->request->post['isbn'])) { + $data['isbn'] = $this->request->post['isbn']; + } elseif (!empty($product_info)) { + $data['isbn'] = $product_info['isbn']; + } else { + $data['isbn'] = ''; + } + + if (isset($this->request->post['mpn'])) { + $data['mpn'] = $this->request->post['mpn']; + } elseif (!empty($product_info)) { + $data['mpn'] = $product_info['mpn']; + } else { + $data['mpn'] = ''; + } + + if (isset($this->request->post['location'])) { + $data['location'] = $this->request->post['location']; + } elseif (!empty($product_info)) { + $data['location'] = $product_info['location']; + } else { + $data['location'] = ''; + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['product_store'])) { + $data['product_store'] = $this->request->post['product_store']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']); + } else { + $data['product_store'] = array(0); + } + + if (isset($this->request->post['shipping'])) { + $data['shipping'] = $this->request->post['shipping']; + } elseif (!empty($product_info)) { + $data['shipping'] = $product_info['shipping']; + } else { + $data['shipping'] = 1; + } + + if (isset($this->request->post['price'])) { + $data['price'] = $this->request->post['price']; + } elseif (!empty($product_info)) { + $data['price'] = $product_info['price']; + } else { + $data['price'] = ''; + } + + $this->load->model('catalog/recurring'); + + $data['recurrings'] = $this->model_catalog_recurring->getRecurrings(); + + if (isset($this->request->post['product_recurrings'])) { + $data['product_recurrings'] = $this->request->post['product_recurrings']; + } elseif (!empty($product_info)) { + $data['product_recurrings'] = $this->model_catalog_product->getRecurrings($product_info['product_id']); + } else { + $data['product_recurrings'] = array(); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['tax_class_id'])) { + $data['tax_class_id'] = $this->request->post['tax_class_id']; + } elseif (!empty($product_info)) { + $data['tax_class_id'] = $product_info['tax_class_id']; + } else { + $data['tax_class_id'] = 0; + } + + if (isset($this->request->post['date_available'])) { + $data['date_available'] = $this->request->post['date_available']; + } elseif (!empty($product_info)) { + $data['date_available'] = ($product_info['date_available'] != '0000-00-00') ? $product_info['date_available'] : ''; + } else { + $data['date_available'] = date('Y-m-d'); + } + + if (isset($this->request->post['quantity'])) { + $data['quantity'] = $this->request->post['quantity']; + } elseif (!empty($product_info)) { + $data['quantity'] = $product_info['quantity']; + } else { + $data['quantity'] = 1; + } + + if (isset($this->request->post['minimum'])) { + $data['minimum'] = $this->request->post['minimum']; + } elseif (!empty($product_info)) { + $data['minimum'] = $product_info['minimum']; + } else { + $data['minimum'] = 1; + } + + if (isset($this->request->post['subtract'])) { + $data['subtract'] = $this->request->post['subtract']; + } elseif (!empty($product_info)) { + $data['subtract'] = $product_info['subtract']; + } else { + $data['subtract'] = 1; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($product_info)) { + $data['sort_order'] = $product_info['sort_order']; + } else { + $data['sort_order'] = 1; + } + + $this->load->model('localisation/stock_status'); + + $data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses(); + + if (isset($this->request->post['stock_status_id'])) { + $data['stock_status_id'] = $this->request->post['stock_status_id']; + } elseif (!empty($product_info)) { + $data['stock_status_id'] = $product_info['stock_status_id']; + } else { + $data['stock_status_id'] = 0; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($product_info)) { + $data['status'] = $product_info['status']; + } else { + $data['status'] = true; + } + + if (isset($this->request->post['weight'])) { + $data['weight'] = $this->request->post['weight']; + } elseif (!empty($product_info)) { + $data['weight'] = $product_info['weight']; + } else { + $data['weight'] = ''; + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['weight_class_id'])) { + $data['weight_class_id'] = $this->request->post['weight_class_id']; + } elseif (!empty($product_info)) { + $data['weight_class_id'] = $product_info['weight_class_id']; + } else { + $data['weight_class_id'] = $this->config->get('config_weight_class_id'); + } + + if (isset($this->request->post['length'])) { + $data['length'] = $this->request->post['length']; + } elseif (!empty($product_info)) { + $data['length'] = $product_info['length']; + } else { + $data['length'] = ''; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($product_info)) { + $data['width'] = $product_info['width']; + } else { + $data['width'] = ''; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($product_info)) { + $data['height'] = $product_info['height']; + } else { + $data['height'] = ''; + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['length_class_id'])) { + $data['length_class_id'] = $this->request->post['length_class_id']; + } elseif (!empty($product_info)) { + $data['length_class_id'] = $product_info['length_class_id']; + } else { + $data['length_class_id'] = $this->config->get('config_length_class_id'); + } + + $this->load->model('catalog/manufacturer'); + + if (isset($this->request->post['manufacturer_id'])) { + $data['manufacturer_id'] = $this->request->post['manufacturer_id']; + } elseif (!empty($product_info)) { + $data['manufacturer_id'] = $product_info['manufacturer_id']; + } else { + $data['manufacturer_id'] = 0; + } + + if (isset($this->request->post['manufacturer'])) { + $data['manufacturer'] = $this->request->post['manufacturer']; + } elseif (!empty($product_info)) { + $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); + + if ($manufacturer_info) { + $data['manufacturer'] = $manufacturer_info['name']; + } else { + $data['manufacturer'] = ''; + } + } else { + $data['manufacturer'] = ''; + } + + // Categories + $this->load->model('catalog/category'); + + if (isset($this->request->post['product_category'])) { + $categories = $this->request->post['product_category']; + } elseif (isset($this->request->get['product_id'])) { + $categories = $this->model_catalog_product->getProductCategories($this->request->get['product_id']); + } else { + $categories = array(); + } + + $data['product_categories'] = array(); + + foreach ($categories as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $data['product_categories'][] = array( + 'category_id' => $category_info['category_id'], + 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] + ); + } + } + + // Filters + $this->load->model('catalog/filter'); + + if (isset($this->request->post['product_filter'])) { + $filters = $this->request->post['product_filter']; + } elseif (isset($this->request->get['product_id'])) { + $filters = $this->model_catalog_product->getProductFilters($this->request->get['product_id']); + } else { + $filters = array(); + } + + $data['product_filters'] = array(); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'name' => $filter_info['group'] . ' > ' . $filter_info['name'] + ); + } + } + + // Attributes + $this->load->model('catalog/attribute'); + + if (isset($this->request->post['product_attribute'])) { + $product_attributes = $this->request->post['product_attribute']; + } elseif (isset($this->request->get['product_id'])) { + $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); + } else { + $product_attributes = array(); + } + + $data['product_attributes'] = array(); + + foreach ($product_attributes as $product_attribute) { + $attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']); + + if ($attribute_info) { + $data['product_attributes'][] = array( + 'attribute_id' => $product_attribute['attribute_id'], + 'name' => $attribute_info['name'], + 'product_attribute_description' => $product_attribute['product_attribute_description'] + ); + } + } + + // Options + $this->load->model('catalog/option'); + + if (isset($this->request->post['product_option'])) { + $product_options = $this->request->post['product_option']; + } elseif (isset($this->request->get['product_id'])) { + $product_options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']); + } else { + $product_options = array(); + } + + $data['product_options'] = array(); + + foreach ($product_options as $product_option) { + $product_option_value_data = array(); + + if (isset($product_option['product_option_value'])) { + foreach ($product_option['product_option_value'] as $product_option_value) { + $product_option_value_data[] = array( + 'product_option_value_id' => $product_option_value['product_option_value_id'], + 'option_value_id' => $product_option_value['option_value_id'], + 'quantity' => $product_option_value['quantity'], + 'subtract' => $product_option_value['subtract'], + 'price' => $product_option_value['price'], + 'price_prefix' => $product_option_value['price_prefix'], + 'points' => $product_option_value['points'], + 'points_prefix' => $product_option_value['points_prefix'], + 'weight' => $product_option_value['weight'], + 'weight_prefix' => $product_option_value['weight_prefix'] + ); + } + } + + $data['product_options'][] = array( + 'product_option_id' => $product_option['product_option_id'], + 'product_option_value' => $product_option_value_data, + 'option_id' => $product_option['option_id'], + 'name' => $product_option['name'], + 'type' => $product_option['type'], + 'value' => isset($product_option['value']) ? $product_option['value'] : '', + 'required' => $product_option['required'] + ); + } + + $data['option_values'] = array(); + + foreach ($data['product_options'] as $product_option) { + if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { + if (!isset($data['option_values'][$product_option['option_id']])) { + $data['option_values'][$product_option['option_id']] = $this->model_catalog_option->getOptionValues($product_option['option_id']); + } + } + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['product_discount'])) { + $product_discounts = $this->request->post['product_discount']; + } elseif (isset($this->request->get['product_id'])) { + $product_discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); + } else { + $product_discounts = array(); + } + + $data['product_discounts'] = array(); + + foreach ($product_discounts as $product_discount) { + $data['product_discounts'][] = array( + 'customer_group_id' => $product_discount['customer_group_id'], + 'quantity' => $product_discount['quantity'], + 'priority' => $product_discount['priority'], + 'price' => $product_discount['price'], + 'date_start' => ($product_discount['date_start'] != '0000-00-00') ? $product_discount['date_start'] : '', + 'date_end' => ($product_discount['date_end'] != '0000-00-00') ? $product_discount['date_end'] : '' + ); + } + + if (isset($this->request->post['product_special'])) { + $product_specials = $this->request->post['product_special']; + } elseif (isset($this->request->get['product_id'])) { + $product_specials = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']); + } else { + $product_specials = array(); + } + + $data['product_specials'] = array(); + + foreach ($product_specials as $product_special) { + $data['product_specials'][] = array( + 'customer_group_id' => $product_special['customer_group_id'], + 'priority' => $product_special['priority'], + 'price' => $product_special['price'], + 'date_start' => ($product_special['date_start'] != '0000-00-00') ? $product_special['date_start'] : '', + 'date_end' => ($product_special['date_end'] != '0000-00-00') ? $product_special['date_end'] : '' + ); + } + + // Image + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($product_info)) { + $data['image'] = $product_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($product_info) && is_file(DIR_IMAGE . $product_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($product_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + // Images + if (isset($this->request->post['product_image'])) { + $product_images = $this->request->post['product_image']; + } elseif (isset($this->request->get['product_id'])) { + $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); + } else { + $product_images = array(); + } + + $data['product_images'] = array(); + + foreach ($product_images as $product_image) { + if (is_file(DIR_IMAGE . $product_image['image'])) { + $image = $product_image['image']; + $thumb = $product_image['image']; + } else { + $image = ''; + $thumb = 'no_image.png'; + } + + $data['product_images'][] = array( + 'image' => $image, + 'thumb' => $this->model_tool_image->resize($thumb, 100, 100), + 'sort_order' => $product_image['sort_order'] + ); + } + + // Downloads + $this->load->model('catalog/download'); + + if (isset($this->request->post['product_download'])) { + $product_downloads = $this->request->post['product_download']; + } elseif (isset($this->request->get['product_id'])) { + $product_downloads = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']); + } else { + $product_downloads = array(); + } + + $data['product_downloads'] = array(); + + foreach ($product_downloads as $download_id) { + $download_info = $this->model_catalog_download->getDownload($download_id); + + if ($download_info) { + $data['product_downloads'][] = array( + 'download_id' => $download_info['download_id'], + 'name' => $download_info['name'] + ); + } + } + + if (isset($this->request->post['product_related'])) { + $products = $this->request->post['product_related']; + } elseif (isset($this->request->get['product_id'])) { + $products = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); + } else { + $products = array(); + } + + $data['product_relateds'] = array(); + + foreach ($products as $product_id) { + $related_info = $this->model_catalog_product->getProduct($product_id); + + if ($related_info) { + $data['product_relateds'][] = array( + 'product_id' => $related_info['product_id'], + 'name' => $related_info['name'] + ); + } + } + + if (isset($this->request->post['points'])) { + $data['points'] = $this->request->post['points']; + } elseif (!empty($product_info)) { + $data['points'] = $product_info['points']; + } else { + $data['points'] = ''; + } + + if (isset($this->request->post['product_reward'])) { + $data['product_reward'] = $this->request->post['product_reward']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_reward'] = $this->model_catalog_product->getProductRewards($this->request->get['product_id']); + } else { + $data['product_reward'] = array(); + } + + if (isset($this->request->post['product_seo_url'])) { + $data['product_seo_url'] = $this->request->post['product_seo_url']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_seo_url'] = $this->model_catalog_product->getProductSeoUrls($this->request->get['product_id']); + } else { + $data['product_seo_url'] = array(); + } + + if (isset($this->request->post['product_layout'])) { + $data['product_layout'] = $this->request->post['product_layout']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_layout'] = $this->model_catalog_product->getProductLayouts($this->request->get['product_id']); + } else { + $data['product_layout'] = array(); + } + + $this->load->model('design/layout'); + + $data['layouts'] = $this->model_design_layout->getLayouts(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/product_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/product')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['product_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 255)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + + if ((utf8_strlen($value['meta_title']) < 1) || (utf8_strlen($value['meta_title']) > 255)) { + $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title'); + } + } + + if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) { + $this->error['model'] = $this->language->get('error_model'); + } + + if ($this->request->post['product_seo_url']) { + $this->load->model('design/seo_url'); + + foreach ($this->request->post['product_seo_url'] as $store_id => $language) { + foreach ($language as $language_id => $keyword) { + if (!empty($keyword)) { + if (count(array_keys($language, $keyword)) > 1) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword); + + foreach ($seo_urls as $seo_url) { + if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['product_id']) || (($seo_url['query'] != 'product_id=' . $this->request->get['product_id'])))) { + $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword'); + + break; + } + } + } + } + } + } + + 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', 'catalog/product')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + protected function validateCopy() { + if (!$this->user->hasPermission('modify', 'catalog/product')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_model'])) { + $this->load->model('catalog/product'); + $this->load->model('catalog/option'); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_model'])) { + $filter_model = $this->request->get['filter_model']; + } else { + $filter_model = ''; + } + + if (isset($this->request->get['limit'])) { + $limit = $this->request->get['limit']; + } else { + $limit = 5; + } + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_model' => $filter_model, + 'start' => 0, + 'limit' => $limit + ); + + $results = $this->model_catalog_product->getProducts($filter_data); + + foreach ($results as $result) { + $option_data = array(); + + $product_options = $this->model_catalog_product->getProductOptions($result['product_id']); + + foreach ($product_options as $product_option) { + $option_info = $this->model_catalog_option->getOption($product_option['option_id']); + + if ($option_info) { + $product_option_value_data = array(); + + foreach ($product_option['product_option_value'] as $product_option_value) { + $option_value_info = $this->model_catalog_option->getOptionValue($product_option_value['option_value_id']); + + if ($option_value_info) { + $product_option_value_data[] = array( + 'product_option_value_id' => $product_option_value['product_option_value_id'], + 'option_value_id' => $product_option_value['option_value_id'], + 'name' => $option_value_info['name'], + 'price' => (float)$product_option_value['price'] ? $this->currency->format($product_option_value['price'], $this->config->get('config_currency')) : false, + 'price_prefix' => $product_option_value['price_prefix'] + ); + } + } + + $option_data[] = array( + 'product_option_id' => $product_option['product_option_id'], + 'product_option_value' => $product_option_value_data, + 'option_id' => $product_option['option_id'], + 'name' => $option_info['name'], + 'type' => $option_info['type'], + 'value' => $product_option['value'], + 'required' => $product_option['required'] + ); + } + } + + $json[] = array( + 'product_id' => $result['product_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), + 'model' => $result['model'], + 'option' => $option_data, + 'price' => $result['price'] + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/catalog/recurring.php b/public/admin/controller/catalog/recurring.php new file mode 100644 index 0000000..7bd9a73 --- /dev/null +++ b/public/admin/controller/catalog/recurring.php @@ -0,0 +1,514 @@ +<?php +class ControllerCatalogRecurring extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/recurring'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/recurring'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_recurring->addRecurring($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/recurring'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_recurring->editRecurring($this->request->get['recurring_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/recurring'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $recurring_id) { + $this->model_catalog_recurring->deleteRecurring($recurring_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function copy() { + $this->load->language('catalog/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/recurring'); + + if (isset($this->request->post['selected']) && $this->validateCopy()) { + foreach ($this->request->post['selected'] as $recurring_id) { + $this->model_catalog_recurring->copyRecurring($recurring_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'rd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/recurring/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['copy'] = $this->url->link('catalog/recurring/copy', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/recurring/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['recurrings'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $recurring_total = $this->model_catalog_recurring->getTotalRecurrings(); + + $results = $this->model_catalog_recurring->getRecurrings($filter_data); + + foreach ($results as $result) { + $data['recurrings'][] = array( + 'recurring_id' => $result['recurring_id'], + 'name' => $result['name'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $result['recurring_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true); + $data['sort_sort_order'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=p.sort_order' . $url, true); + + $url = ''; + + 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 = $recurring_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($recurring_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($recurring_total - $this->config->get('config_limit_admin'))) ? $recurring_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $recurring_total, ceil($recurring_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/recurring_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['recurring_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['recurring_id'])) { + $data['action'] = $this->url->link('catalog/recurring/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $this->request->get['recurring_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['recurring_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $recurring_info = $this->model_catalog_recurring->getRecurring($this->request->get['recurring_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['recurring_description'])) { + $data['recurring_description'] = $this->request->post['recurring_description']; + } elseif (!empty($recurring_info)) { + $data['recurring_description'] = $this->model_catalog_recurring->getRecurringDescription($recurring_info['recurring_id']); + } else { + $data['recurring_description'] = array(); + } + + if (isset($this->request->post['price'])) { + $data['price'] = $this->request->post['price']; + } elseif (!empty($recurring_info)) { + $data['price'] = $recurring_info['price']; + } else { + $data['price'] = 0; + } + + $data['frequencies'] = array(); + + $data['frequencies'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day' + ); + + $data['frequencies'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week' + ); + + $data['frequencies'][] = array( + 'text' => $this->language->get('text_semi_month'), + 'value' => 'semi_month' + ); + + $data['frequencies'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month' + ); + + $data['frequencies'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year' + ); + + if (isset($this->request->post['frequency'])) { + $data['frequency'] = $this->request->post['frequency']; + } elseif (!empty($recurring_info)) { + $data['frequency'] = $recurring_info['frequency']; + } else { + $data['frequency'] = ''; + } + + if (isset($this->request->post['duration'])) { + $data['duration'] = $this->request->post['duration']; + } elseif (!empty($recurring_info)) { + $data['duration'] = $recurring_info['duration']; + } else { + $data['duration'] = 0; + } + + if (isset($this->request->post['cycle'])) { + $data['cycle'] = $this->request->post['cycle']; + } elseif (!empty($recurring_info)) { + $data['cycle'] = $recurring_info['cycle']; + } else { + $data['cycle'] = 1; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($recurring_info)) { + $data['status'] = $recurring_info['status']; + } else { + $data['status'] = 0; + } + + if (isset($this->request->post['trial_price'])) { + $data['trial_price'] = $this->request->post['trial_price']; + } elseif (!empty($recurring_info)) { + $data['trial_price'] = $recurring_info['trial_price']; + } else { + $data['trial_price'] = 0.00; + } + + if (isset($this->request->post['trial_frequency'])) { + $data['trial_frequency'] = $this->request->post['trial_frequency']; + } elseif (!empty($recurring_info)) { + $data['trial_frequency'] = $recurring_info['trial_frequency']; + } else { + $data['trial_frequency'] = ''; + } + + if (isset($this->request->post['trial_duration'])) { + $data['trial_duration'] = $this->request->post['trial_duration']; + } elseif (!empty($recurring_info)) { + $data['trial_duration'] = $recurring_info['trial_duration']; + } else { + $data['trial_duration'] = '0'; + } + + if (isset($this->request->post['trial_cycle'])) { + $data['trial_cycle'] = $this->request->post['trial_cycle']; + } elseif (!empty($recurring_info)) { + $data['trial_cycle'] = $recurring_info['trial_cycle']; + } else { + $data['trial_cycle'] = '1'; + } + if (isset($this->request->post['trial_status'])) { + $data['trial_status'] = $this->request->post['trial_status']; + } elseif (!empty($recurring_info)) { + $data['trial_status'] = $recurring_info['trial_status']; + } else { + $data['trial_status'] = 0; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($recurring_info)) { + $data['sort_order'] = $recurring_info['sort_order']; + } else { + $data['sort_order'] = 0; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/recurring_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/recurring')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['recurring_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 255)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + 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', 'catalog/recurring')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $recurring_id) { + $product_total = $this->model_catalog_product->getTotalProductsByProfileId($recurring_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } + + protected function validateCopy() { + if (!$this->user->hasPermission('modify', 'catalog/recurring')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/catalog/review.php b/public/admin/controller/catalog/review.php new file mode 100644 index 0000000..71e2106 --- /dev/null +++ b/public/admin/controller/catalog/review.php @@ -0,0 +1,570 @@ +<?php +class ControllerCatalogReview extends Controller { + private $error = array(); + + public function index() { + $this->load->language('catalog/review'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/review'); + + $this->getList(); + } + + public function add() { + $this->load->language('catalog/review'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/review'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_review->addReview($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('catalog/review'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/review'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_catalog_review->editReview($this->request->get['review_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('catalog/review'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('catalog/review'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $review_id) { + $this->model_catalog_review->deleteReview($review_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_product'])) { + $filter_product = $this->request->get['filter_product']; + } else { + $filter_product = ''; + } + + if (isset($this->request->get['filter_author'])) { + $filter_author = $this->request->get['filter_author']; + } else { + $filter_author = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'r.date_added'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('catalog/review/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('catalog/review/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['reviews'] = array(); + + $filter_data = array( + 'filter_product' => $filter_product, + 'filter_author' => $filter_author, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $review_total = $this->model_catalog_review->getTotalReviews($filter_data); + + $results = $this->model_catalog_review->getReviews($filter_data); + + foreach ($results as $result) { + $data['reviews'][] = array( + 'review_id' => $result['review_id'], + 'name' => $result['name'], + 'author' => $result['author'], + 'rating' => $result['rating'], + 'status' => ($result['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('catalog/review/edit', 'user_token=' . $this->session->data['user_token'] . '&review_id=' . $result['review_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_product'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true); + $data['sort_author'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.author' . $url, true); + $data['sort_rating'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.rating' . $url, true); + $data['sort_status'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.status' . $url, true); + $data['sort_date_added'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $review_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($review_total - $this->config->get('config_limit_admin'))) ? $review_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $review_total, ceil($review_total / $this->config->get('config_limit_admin'))); + + $data['filter_product'] = $filter_product; + $data['filter_author'] = $filter_author; + $data['filter_status'] = $filter_status; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/review_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['review_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['product'])) { + $data['error_product'] = $this->error['product']; + } else { + $data['error_product'] = ''; + } + + if (isset($this->error['author'])) { + $data['error_author'] = $this->error['author']; + } else { + $data['error_author'] = ''; + } + + if (isset($this->error['text'])) { + $data['error_text'] = $this->error['text']; + } else { + $data['error_text'] = ''; + } + + if (isset($this->error['rating'])) { + $data['error_rating'] = $this->error['rating']; + } else { + $data['error_rating'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_author'])) { + $url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['review_id'])) { + $data['action'] = $this->url->link('catalog/review/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('catalog/review/edit', 'user_token=' . $this->session->data['user_token'] . '&review_id=' . $this->request->get['review_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['review_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $review_info = $this->model_catalog_review->getReview($this->request->get['review_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('catalog/product'); + + if (isset($this->request->post['product_id'])) { + $data['product_id'] = $this->request->post['product_id']; + } elseif (!empty($review_info)) { + $data['product_id'] = $review_info['product_id']; + } else { + $data['product_id'] = ''; + } + + if (isset($this->request->post['product'])) { + $data['product'] = $this->request->post['product']; + } elseif (!empty($review_info)) { + $data['product'] = $review_info['product']; + } else { + $data['product'] = ''; + } + + if (isset($this->request->post['author'])) { + $data['author'] = $this->request->post['author']; + } elseif (!empty($review_info)) { + $data['author'] = $review_info['author']; + } else { + $data['author'] = ''; + } + + if (isset($this->request->post['text'])) { + $data['text'] = $this->request->post['text']; + } elseif (!empty($review_info)) { + $data['text'] = $review_info['text']; + } else { + $data['text'] = ''; + } + + if (isset($this->request->post['rating'])) { + $data['rating'] = $this->request->post['rating']; + } elseif (!empty($review_info)) { + $data['rating'] = $review_info['rating']; + } else { + $data['rating'] = ''; + } + + if (isset($this->request->post['date_added'])) { + $data['date_added'] = $this->request->post['date_added']; + } elseif (!empty($review_info)) { + $data['date_added'] = ($review_info['date_added'] != '0000-00-00 00:00' ? $review_info['date_added'] : ''); + } else { + $data['date_added'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($review_info)) { + $data['status'] = $review_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('catalog/review_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'catalog/review')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['product_id']) { + $this->error['product'] = $this->language->get('error_product'); + } + + if ((utf8_strlen($this->request->post['author']) < 3) || (utf8_strlen($this->request->post['author']) > 64)) { + $this->error['author'] = $this->language->get('error_author'); + } + + if (utf8_strlen($this->request->post['text']) < 1) { + $this->error['text'] = $this->language->get('error_text'); + } + + if (!isset($this->request->post['rating']) || $this->request->post['rating'] < 0 || $this->request->post['rating'] > 5) { + $this->error['rating'] = $this->language->get('error_rating'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'catalog/review')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/column_left.php b/public/admin/controller/common/column_left.php new file mode 100644 index 0000000..54b1209 --- /dev/null +++ b/public/admin/controller/common/column_left.php @@ -0,0 +1,698 @@ +<?php +class ControllerCommonColumnLeft extends Controller { + public function index() { + if (isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { + $this->load->language('common/column_left'); + + // Create a 3 level menu array + // Level 2 can not have children + + // Menu + $data['menus'][] = array( + 'id' => 'menu-dashboard', + 'icon' => 'fa-dashboard', + 'name' => $this->language->get('text_dashboard'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + // Catalog + $catalog = array(); + + if ($this->user->hasPermission('access', 'catalog/category')) { + $catalog[] = array( + 'name' => $this->language->get('text_category'), + 'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/product')) { + $catalog[] = array( + 'name' => $this->language->get('text_product'), + 'href' => $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/recurring')) { + $catalog[] = array( + 'name' => $this->language->get('text_recurring'), + 'href' => $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/filter')) { + $catalog[] = array( + 'name' => $this->language->get('text_filter'), + 'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + // Attributes + $attribute = array(); + + if ($this->user->hasPermission('access', 'catalog/attribute')) { + $attribute[] = array( + 'name' => $this->language->get('text_attribute'), + 'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/attribute_group')) { + $attribute[] = array( + 'name' => $this->language->get('text_attribute_group'), + 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($attribute) { + $catalog[] = array( + 'name' => $this->language->get('text_attribute'), + 'href' => '', + 'children' => $attribute + ); + } + + if ($this->user->hasPermission('access', 'catalog/option')) { + $catalog[] = array( + 'name' => $this->language->get('text_option'), + 'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/manufacturer')) { + $catalog[] = array( + 'name' => $this->language->get('text_manufacturer'), + 'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/download')) { + $catalog[] = array( + 'name' => $this->language->get('text_download'), + 'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/review')) { + $catalog[] = array( + 'name' => $this->language->get('text_review'), + 'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'catalog/information')) { + $catalog[] = array( + 'name' => $this->language->get('text_information'), + 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($catalog) { + $data['menus'][] = array( + 'id' => 'menu-catalog', + 'icon' => 'fa-tags', + 'name' => $this->language->get('text_catalog'), + 'href' => '', + 'children' => $catalog + ); + } + + // Extension + $marketplace = array(); + + if ($this->user->hasPermission('access', 'marketplace/marketplace')) { + $marketplace[] = array( + 'name' => $this->language->get('text_marketplace'), + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketplace/installer')) { + $marketplace[] = array( + 'name' => $this->language->get('text_installer'), + 'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketplace/extension')) { + $marketplace[] = array( + 'name' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketplace/modification')) { + $marketplace[] = array( + 'name' => $this->language->get('text_modification'), + 'href' => $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketplace/event')) { + $marketplace[] = array( + 'name' => $this->language->get('text_event'), + 'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($marketplace) { + $data['menus'][] = array( + 'id' => 'menu-extension', + 'icon' => 'fa-puzzle-piece', + 'name' => $this->language->get('text_extension'), + 'href' => '', + 'children' => $marketplace + ); + } + + // Design + $design = array(); + + if ($this->user->hasPermission('access', 'design/layout')) { + $design[] = array( + 'name' => $this->language->get('text_layout'), + 'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'design/theme')) { + $design[] = array( + 'name' => $this->language->get('text_theme'), + 'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'design/translation')) { + $design[] = array( + 'name' => $this->language->get('text_language_editor'), + 'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'design/banner')) { + $design[] = array( + 'name' => $this->language->get('text_banner'), + 'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'design/seo_url')) { + $design[] = array( + 'name' => $this->language->get('text_seo_url'), + 'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($design) { + $data['menus'][] = array( + 'id' => 'menu-design', + 'icon' => 'fa-television', + 'name' => $this->language->get('text_design'), + 'href' => '', + 'children' => $design + ); + } + + // Sales + $sale = array(); + + if ($this->user->hasPermission('access', 'sale/order')) { + $sale[] = array( + 'name' => $this->language->get('text_order'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'sale/recurring')) { + $sale[] = array( + 'name' => $this->language->get('text_recurring'), + 'href' => $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'sale/return')) { + $sale[] = array( + 'name' => $this->language->get('text_return'), + 'href' => $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + // Voucher + $voucher = array(); + + if ($this->user->hasPermission('access', 'sale/voucher')) { + $voucher[] = array( + 'name' => $this->language->get('text_voucher'), + 'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'sale/voucher_theme')) { + $voucher[] = array( + 'name' => $this->language->get('text_voucher_theme'), + 'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($voucher) { + $sale[] = array( + 'name' => $this->language->get('text_voucher'), + 'href' => '', + 'children' => $voucher + ); + } + + if ($sale) { + $data['menus'][] = array( + 'id' => 'menu-sale', + 'icon' => 'fa-shopping-cart', + 'name' => $this->language->get('text_sale'), + 'href' => '', + 'children' => $sale + ); + } + + // Customer + $customer = array(); + + if ($this->user->hasPermission('access', 'customer/customer')) { + $customer[] = array( + 'name' => $this->language->get('text_customer'), + 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'customer/customer_group')) { + $customer[] = array( + 'name' => $this->language->get('text_customer_group'), + 'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'customer/customer_approval')) { + $customer[] = array( + 'name' => $this->language->get('text_customer_approval'), + 'href' => $this->url->link('customer/customer_approval', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'customer/custom_field')) { + $customer[] = array( + 'name' => $this->language->get('text_custom_field'), + 'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($customer) { + $data['menus'][] = array( + 'id' => 'menu-customer', + 'icon' => 'fa-user', + 'name' => $this->language->get('text_customer'), + 'href' => '', + 'children' => $customer + ); + } + + // Marketing + $marketing = array(); + + if ($this->user->hasPermission('access', 'marketing/marketing')) { + $marketing[] = array( + 'name' => $this->language->get('text_marketing'), + 'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketing/coupon')) { + $marketing[] = array( + 'name' => $this->language->get('text_coupon'), + 'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'marketing/contact')) { + $marketing[] = array( + 'name' => $this->language->get('text_contact'), + 'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($marketing) { + $data['menus'][] = array( + 'id' => 'menu-marketing', + 'icon' => 'fa-share-alt', + 'name' => $this->language->get('text_marketing'), + 'href' => '', + 'children' => $marketing + ); + } + + // System + $system = array(); + + if ($this->user->hasPermission('access', 'setting/setting')) { + $system[] = array( + 'name' => $this->language->get('text_setting'), + 'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + // Users + $user = array(); + + if ($this->user->hasPermission('access', 'user/user')) { + $user[] = array( + 'name' => $this->language->get('text_users'), + 'href' => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'user/user_permission')) { + $user[] = array( + 'name' => $this->language->get('text_user_group'), + 'href' => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'user/api')) { + $user[] = array( + 'name' => $this->language->get('text_api'), + 'href' => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($user) { + $system[] = array( + 'name' => $this->language->get('text_users'), + 'href' => '', + 'children' => $user + ); + } + + // Localisation + $localisation = array(); + + if ($this->user->hasPermission('access', 'localisation/location')) { + $localisation[] = array( + 'name' => $this->language->get('text_location'), + 'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/language')) { + $localisation[] = array( + 'name' => $this->language->get('text_language'), + 'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/currency')) { + $localisation[] = array( + 'name' => $this->language->get('text_currency'), + 'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/stock_status')) { + $localisation[] = array( + 'name' => $this->language->get('text_stock_status'), + 'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/order_status')) { + $localisation[] = array( + 'name' => $this->language->get('text_order_status'), + 'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + // Returns + $return = array(); + + if ($this->user->hasPermission('access', 'localisation/return_status')) { + $return[] = array( + 'name' => $this->language->get('text_return_status'), + 'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/return_action')) { + $return[] = array( + 'name' => $this->language->get('text_return_action'), + 'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/return_reason')) { + $return[] = array( + 'name' => $this->language->get('text_return_reason'), + 'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($return) { + $localisation[] = array( + 'name' => $this->language->get('text_return'), + 'href' => '', + 'children' => $return + ); + } + + if ($this->user->hasPermission('access', 'localisation/country')) { + $localisation[] = array( + 'name' => $this->language->get('text_country'), + 'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/zone')) { + $localisation[] = array( + 'name' => $this->language->get('text_zone'), + 'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/geo_zone')) { + $localisation[] = array( + 'name' => $this->language->get('text_geo_zone'), + 'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + // Tax + $tax = array(); + + if ($this->user->hasPermission('access', 'localisation/tax_class')) { + $tax[] = array( + 'name' => $this->language->get('text_tax_class'), + 'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/tax_rate')) { + $tax[] = array( + 'name' => $this->language->get('text_tax_rate'), + 'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($tax) { + $localisation[] = array( + 'name' => $this->language->get('text_tax'), + 'href' => '', + 'children' => $tax + ); + } + + if ($this->user->hasPermission('access', 'localisation/length_class')) { + $localisation[] = array( + 'name' => $this->language->get('text_length_class'), + 'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'localisation/weight_class')) { + $localisation[] = array( + 'name' => $this->language->get('text_weight_class'), + 'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($localisation) { + $system[] = array( + 'name' => $this->language->get('text_localisation'), + 'href' => '', + 'children' => $localisation + ); + } + + // Tools + $maintenance = array(); + + if ($this->user->hasPermission('access', 'tool/backup')) { + $maintenance[] = array( + 'name' => $this->language->get('text_backup'), + 'href' => $this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'tool/upload')) { + $maintenance[] = array( + 'name' => $this->language->get('text_upload'), + 'href' => $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'tool/log')) { + $maintenance[] = array( + 'name' => $this->language->get('text_log'), + 'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($maintenance) { + $system[] = array( + 'id' => 'menu-maintenance', + 'icon' => 'fa-cog', + 'name' => $this->language->get('text_maintenance'), + 'href' => '', + 'children' => $maintenance + ); + } + + + if ($system) { + $data['menus'][] = array( + 'id' => 'menu-system', + 'icon' => 'fa-cog', + 'name' => $this->language->get('text_system'), + 'href' => '', + 'children' => $system + ); + } + + $report = array(); + + if ($this->user->hasPermission('access', 'report/report')) { + $report[] = array( + 'name' => $this->language->get('text_reports'), + 'href' => $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'report/online')) { + $report[] = array( + 'name' => $this->language->get('text_online'), + 'href' => $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($this->user->hasPermission('access', 'report/statistics')) { + $report[] = array( + 'name' => $this->language->get('text_statistics'), + 'href' => $this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + $data['menus'][] = array( + 'id' => 'menu-report', + 'icon' => 'fa-bar-chart-o', + 'name' => $this->language->get('text_reports'), + 'href' => '', + 'children' => $report + ); + + // Stats + $this->load->model('sale/order'); + + $order_total = $this->model_sale_order->getTotalOrders(); + + $this->load->model('report/statistics'); + + $complete_total = $this->model_report_statistics->getValue('order_complete'); + + if ((float)$complete_total && $order_total) { + $data['complete_status'] = round(($complete_total / $order_total) * 100); + } else { + $data['complete_status'] = 0; + } + + $processing_total = $this->model_report_statistics->getValue('order_processing'); + + if ((float)$processing_total && $order_total) { + $data['processing_status'] = round(($processing_total / $order_total) * 100); + } else { + $data['processing_status'] = 0; + } + + $other_total = $this->model_report_statistics->getValue('order_other'); + + if ((float)$other_total && $order_total) { + $data['other_status'] = round(($other_total / $order_total) * 100); + } else { + $data['other_status'] = 0; + } + + return $this->load->view('common/column_left', $data); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/dashboard.php b/public/admin/controller/common/dashboard.php new file mode 100644 index 0000000..87de219 --- /dev/null +++ b/public/admin/controller/common/dashboard.php @@ -0,0 +1,98 @@ +<?php +class ControllerCommonDashboard extends Controller { + public function index() { + $this->load->language('common/dashboard'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + // Check install directory exists + if (is_dir(DIR_APPLICATION . 'install')) { + $data['error_install'] = $this->language->get('error_install'); + } else { + $data['error_install'] = ''; + } + + // Dashboard Extensions + $dashboards = array(); + + $this->load->model('setting/extension'); + + // Get a list of installed modules + $extensions = $this->model_setting_extension->getInstalled('dashboard'); + + // Add all the modules which have multiple settings for each module + foreach ($extensions as $code) { + if ($this->config->get('dashboard_' . $code . '_status') && $this->user->hasPermission('access', 'extension/dashboard/' . $code)) { + $output = $this->load->controller('extension/dashboard/' . $code . '/dashboard'); + + if ($output) { + $dashboards[] = array( + 'code' => $code, + 'width' => $this->config->get('dashboard_' . $code . '_width'), + 'sort_order' => $this->config->get('dashboard_' . $code . '_sort_order'), + 'output' => $output + ); + } + } + } + + $sort_order = array(); + + foreach ($dashboards as $key => $value) { + $sort_order[$key] = $value['sort_order']; + } + + array_multisort($sort_order, SORT_ASC, $dashboards); + + // Split the array so the columns width is not more than 12 on each row. + $width = 0; + $column = array(); + $data['rows'] = array(); + + foreach ($dashboards as $dashboard) { + $column[] = $dashboard; + + $width = ($width + $dashboard['width']); + + if ($width >= 12) { + $data['rows'][] = $column; + + $width = 0; + $column = array(); + } + } + + if (DIR_STORAGE == DIR_SYSTEM . 'storage/') { + $data['security'] = $this->load->controller('common/security'); + } else { + $data['security'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + // Run currency update + if ($this->config->get('config_currency_auto')) { + $this->load->model('localisation/currency'); + + $this->model_localisation_currency->refresh(); + } + + $this->response->setOutput($this->load->view('common/dashboard', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/developer.php b/public/admin/controller/common/developer.php new file mode 100644 index 0000000..30663dc --- /dev/null +++ b/public/admin/controller/common/developer.php @@ -0,0 +1,113 @@ +<?php +class ControllerCommonDeveloper extends Controller { + public function index() { + $this->load->language('common/developer'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['developer_theme'] = $this->config->get('developer_theme'); + $data['developer_sass'] = $this->config->get('developer_sass'); + + $eval = false; + + $eval = '$eval = true;'; + + eval($eval); + + if ($eval === true) { + $data['eval'] = true; + } else { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('developer', array('developer_theme' => 1), 0); + + $data['eval'] = false; + } + + $this->response->setOutput($this->load->view('common/developer', $data)); + } + + public function edit() { + $this->load->language('common/developer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'common/developer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('developer', $this->request->post, 0); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function theme() { + $this->load->language('common/developer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'common/developer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $directories = glob(DIR_CACHE . '*', GLOB_ONLYDIR); + + if ($directories) { + foreach ($directories as $directory) { + $files = glob($directory . '/*'); + + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } + } + + if (is_dir($directory)) { + rmdir($directory); + } + } + } + + $json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_theme')); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function sass() { + $this->load->language('common/developer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'common/developer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + // Before we delete we need to make sure there is a sass file to regenerate the css + $file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css'; + + if (is_file($file) && is_file(DIR_APPLICATION . 'view/stylesheet/sass/_bootstrap.scss')) { + unlink($file); + } + + $files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/sass/_bootstrap.scss'); + + foreach ($files as $file) { + $file = substr($file, 0, -21) . '/bootstrap.css'; + + if (is_file($file)) { + unlink($file); + } + } + + $json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_sass')); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/filemanager.php b/public/admin/controller/common/filemanager.php new file mode 100644 index 0000000..2b63851 --- /dev/null +++ b/public/admin/controller/common/filemanager.php @@ -0,0 +1,415 @@ +<?php +class ControllerCommonFileManager extends Controller { + public function index() { + $this->load->language('common/filemanager'); + + // Find which protocol to use to pass the full image link back + if ($this->request->server['HTTPS']) { + $server = HTTPS_CATALOG; + } else { + $server = HTTP_CATALOG; + } + + if (isset($this->request->get['filter_name'])) { + $filter_name = rtrim(str_replace(array('*', '/', '\\'), '', $this->request->get['filter_name']), '/'); + } else { + $filter_name = ''; + } + + // Make sure we have the correct directory + if (isset($this->request->get['directory'])) { + $directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace('*', '', $this->request->get['directory']), '/'); + } else { + $directory = DIR_IMAGE . 'catalog'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $directories = array(); + $files = array(); + + $data['images'] = array(); + + $this->load->model('tool/image'); + + if (substr(str_replace('\\', '/', realpath($directory) . '/' . $filter_name), 0, strlen(DIR_IMAGE . 'catalog')) == str_replace('\\', '/', DIR_IMAGE . 'catalog')) { + // Get directories + $directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR); + + if (!$directories) { + $directories = array(); + } + + // Get files + $files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE); + + if (!$files) { + $files = array(); + } + } + + // Merge directories and files + $images = array_merge($directories, $files); + + // Get total number of files and directories + $image_total = count($images); + + // Split the array based on current page number and max number of items per page of 10 + $images = array_splice($images, ($page - 1) * 16, 16); + + foreach ($images as $image) { + $name = str_split(basename($image), 14); + + if (is_dir($image)) { + $url = ''; + + if (isset($this->request->get['target'])) { + $url .= '&target=' . $this->request->get['target']; + } + + if (isset($this->request->get['thumb'])) { + $url .= '&thumb=' . $this->request->get['thumb']; + } + + $data['images'][] = array( + 'thumb' => '', + 'name' => implode(' ', $name), + 'type' => 'directory', + 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), + 'href' => $this->url->link('common/filemanager', 'user_token=' . $this->session->data['user_token'] . '&directory=' . urlencode(utf8_substr($image, utf8_strlen(DIR_IMAGE . 'catalog/'))) . $url, true) + ); + } elseif (is_file($image)) { + $data['images'][] = array( + 'thumb' => $this->model_tool_image->resize(utf8_substr($image, utf8_strlen(DIR_IMAGE)), 100, 100), + 'name' => implode(' ', $name), + 'type' => 'image', + 'path' => utf8_substr($image, utf8_strlen(DIR_IMAGE)), + 'href' => $server . 'image/' . utf8_substr($image, utf8_strlen(DIR_IMAGE)) + ); + } + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['directory'])) { + $data['directory'] = urlencode($this->request->get['directory']); + } else { + $data['directory'] = ''; + } + + if (isset($this->request->get['filter_name'])) { + $data['filter_name'] = $this->request->get['filter_name']; + } else { + $data['filter_name'] = ''; + } + + // Return the target ID for the file manager to set the value + if (isset($this->request->get['target'])) { + $data['target'] = $this->request->get['target']; + } else { + $data['target'] = ''; + } + + // Return the thumbnail for the file manager to show a thumbnail + if (isset($this->request->get['thumb'])) { + $data['thumb'] = $this->request->get['thumb']; + } else { + $data['thumb'] = ''; + } + + // Parent + $url = ''; + + if (isset($this->request->get['directory'])) { + $pos = strrpos($this->request->get['directory'], '/'); + + if ($pos) { + $url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos)); + } + } + + if (isset($this->request->get['target'])) { + $url .= '&target=' . $this->request->get['target']; + } + + if (isset($this->request->get['thumb'])) { + $url .= '&thumb=' . $this->request->get['thumb']; + } + + $data['parent'] = $this->url->link('common/filemanager', 'user_token=' . $this->session->data['user_token'] . $url, true); + + // Refresh + $url = ''; + + if (isset($this->request->get['directory'])) { + $url .= '&directory=' . urlencode($this->request->get['directory']); + } + + if (isset($this->request->get['target'])) { + $url .= '&target=' . $this->request->get['target']; + } + + if (isset($this->request->get['thumb'])) { + $url .= '&thumb=' . $this->request->get['thumb']; + } + + $data['refresh'] = $this->url->link('common/filemanager', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $url = ''; + + if (isset($this->request->get['directory'])) { + $url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['target'])) { + $url .= '&target=' . $this->request->get['target']; + } + + if (isset($this->request->get['thumb'])) { + $url .= '&thumb=' . $this->request->get['thumb']; + } + + $pagination = new Pagination(); + $pagination->total = $image_total; + $pagination->page = $page; + $pagination->limit = 16; + $pagination->url = $this->url->link('common/filemanager', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $this->response->setOutput($this->load->view('common/filemanager', $data)); + } + + public function upload() { + $this->load->language('common/filemanager'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'common/filemanager')) { + $json['error'] = $this->language->get('error_permission'); + } + + // Make sure we have the correct directory + if (isset($this->request->get['directory'])) { + $directory = rtrim(DIR_IMAGE . 'catalog/' . $this->request->get['directory'], '/'); + } else { + $directory = DIR_IMAGE . 'catalog'; + } + + // Check its a directory + if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)), 0, strlen(DIR_IMAGE . 'catalog')) != str_replace('\\', '/', DIR_IMAGE . 'catalog')) { + $json['error'] = $this->language->get('error_directory'); + } + + if (!$json) { + // Check if multiple files are uploaded or just one + $files = array(); + + if (!empty($this->request->files['file']['name']) && is_array($this->request->files['file']['name'])) { + foreach (array_keys($this->request->files['file']['name']) as $key) { + $files[] = array( + 'name' => $this->request->files['file']['name'][$key], + 'type' => $this->request->files['file']['type'][$key], + 'tmp_name' => $this->request->files['file']['tmp_name'][$key], + 'error' => $this->request->files['file']['error'][$key], + 'size' => $this->request->files['file']['size'][$key] + ); + } + } + + foreach ($files as $file) { + if (is_file($file['tmp_name'])) { + // Sanitize the filename + $filename = basename(html_entity_decode($file['name'], ENT_QUOTES, 'UTF-8')); + + // Validate the filename length + if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 255)) { + $json['error'] = $this->language->get('error_filename'); + } + + // Allowed file extension types + $allowed = array( + 'jpg', + 'jpeg', + 'gif', + 'png' + ); + + if (!in_array(utf8_strtolower(utf8_substr(strrchr($filename, '.'), 1)), $allowed)) { + $json['error'] = $this->language->get('error_filetype'); + } + + // Allowed file mime types + $allowed = array( + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png', + 'image/gif' + ); + + if (!in_array($file['type'], $allowed)) { + $json['error'] = $this->language->get('error_filetype'); + } + + // Return any upload error + if ($file['error'] != UPLOAD_ERR_OK) { + $json['error'] = $this->language->get('error_upload_' . $file['error']); + } + } else { + $json['error'] = $this->language->get('error_upload'); + } + + if (!$json) { + move_uploaded_file($file['tmp_name'], $directory . '/' . $filename); + } + } + } + + if (!$json) { + $json['success'] = $this->language->get('text_uploaded'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function folder() { + $this->load->language('common/filemanager'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'common/filemanager')) { + $json['error'] = $this->language->get('error_permission'); + } + + // Make sure we have the correct directory + if (isset($this->request->get['directory'])) { + $directory = rtrim(DIR_IMAGE . 'catalog/' . $this->request->get['directory'], '/'); + } else { + $directory = DIR_IMAGE . 'catalog'; + } + + // Check its a directory + if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)), 0, strlen(DIR_IMAGE . 'catalog')) != str_replace('\\', '/', DIR_IMAGE . 'catalog')) { + $json['error'] = $this->language->get('error_directory'); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + // Sanitize the folder name + $folder = basename(html_entity_decode($this->request->post['folder'], ENT_QUOTES, 'UTF-8')); + + // Validate the filename length + if ((utf8_strlen($folder) < 3) || (utf8_strlen($folder) > 128)) { + $json['error'] = $this->language->get('error_folder'); + } + + // Check if directory already exists or not + if (is_dir($directory . '/' . $folder)) { + $json['error'] = $this->language->get('error_exists'); + } + } + + if (!isset($json['error'])) { + mkdir($directory . '/' . $folder, 0777); + chmod($directory . '/' . $folder, 0777); + + @touch($directory . '/' . $folder . '/' . 'index.html'); + + $json['success'] = $this->language->get('text_directory'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function delete() { + $this->load->language('common/filemanager'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'common/filemanager')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (isset($this->request->post['path'])) { + $paths = $this->request->post['path']; + } else { + $paths = array(); + } + + // Loop through each path to run validations + foreach ($paths as $path) { + // Check path exsists + if ($path == DIR_IMAGE . 'catalog' || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $path)), 0, strlen(DIR_IMAGE . 'catalog')) != str_replace('\\', '/', DIR_IMAGE . 'catalog')) { + $json['error'] = $this->language->get('error_delete'); + + break; + } + } + + if (!$json) { + // Loop through each path + foreach ($paths as $path) { + $path = rtrim(DIR_IMAGE . $path, '/'); + + // If path is just a file delete it + if (is_file($path)) { + unlink($path); + + // If path is a directory beging deleting each file and sub folder + } elseif (is_dir($path)) { + $files = array(); + + // Make path into an array + $path = array($path); + + // While the path array is still populated keep looping through + while (count($path) != 0) { + $next = array_shift($path); + + foreach (glob($next) as $file) { + // If directory add to path array + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + // Add the file to the files to be deleted array + $files[] = $file; + } + } + + // Reverse sort the file array + rsort($files); + + foreach ($files as $file) { + // If file just delete + if (is_file($file)) { + unlink($file); + + // If directory use the remove directory function + } elseif (is_dir($file)) { + rmdir($file); + } + } + } + } + + $json['success'] = $this->language->get('text_delete'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/footer.php b/public/admin/controller/common/footer.php new file mode 100644 index 0000000..ae6a2ab --- /dev/null +++ b/public/admin/controller/common/footer.php @@ -0,0 +1,14 @@ +<?php +class ControllerCommonFooter extends Controller { + public function index() { + $this->load->language('common/footer'); + + if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { + $data['text_version'] = sprintf($this->language->get('text_version'), VERSION); + } else { + $data['text_version'] = ''; + } + + return $this->load->view('common/footer', $data); + } +} diff --git a/public/admin/controller/common/forgotten.php b/public/admin/controller/common/forgotten.php new file mode 100644 index 0000000..7f147ce --- /dev/null +++ b/public/admin/controller/common/forgotten.php @@ -0,0 +1,71 @@ +<?php +class ControllerCommonForgotten extends Controller { + private $error = array(); + + public function index() { + if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { + $this->response->redirect($this->url->link('common/dashboard', '', true)); + } + + if (!$this->config->get('config_password')) { + $this->response->redirect($this->url->link('common/login', '', true)); + } + + $this->load->language('common/forgotten'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_user_user->editCode($this->request->post['email'], token(40)); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('common/login', '', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', '', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('common/forgotten', 'user_token=' . '', true) + ); + + $data['action'] = $this->url->link('common/forgotten', '', true); + + $data['cancel'] = $this->url->link('common/login', '', true); + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } else { + $data['email'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('common/forgotten', $data)); + } + + protected function validate() { + if (!isset($this->request->post['email'])) { + $this->error['warning'] = $this->language->get('error_email'); + } elseif (!$this->model_user_user->getTotalUsersByEmail($this->request->post['email'])) { + $this->error['warning'] = $this->language->get('error_email'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/header.php b/public/admin/controller/common/header.php new file mode 100644 index 0000000..a0eb58a --- /dev/null +++ b/public/admin/controller/common/header.php @@ -0,0 +1,81 @@ +<?php +class ControllerCommonHeader extends Controller { + public function index() { + $data['title'] = $this->document->getTitle(); + + if ($this->request->server['HTTPS']) { + $data['base'] = HTTPS_SERVER; + } else { + $data['base'] = HTTP_SERVER; + } + + $data['description'] = $this->document->getDescription(); + $data['keywords'] = $this->document->getKeywords(); + $data['links'] = $this->document->getLinks(); + $data['styles'] = $this->document->getStyles(); + $data['scripts'] = $this->document->getScripts(); + $data['lang'] = $this->language->get('code'); + $data['direction'] = $this->language->get('direction'); + + $this->load->language('common/header'); + + $data['text_logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName()); + + if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token'])) { + $data['logged'] = ''; + + $data['home'] = $this->url->link('common/dashboard', '', true); + } else { + $data['logged'] = true; + + $data['home'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true); + $data['logout'] = $this->url->link('common/logout', 'user_token=' . $this->session->data['user_token'], true); + $data['profile'] = $this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true); + + $this->load->model('user/user'); + + $this->load->model('tool/image'); + + $user_info = $this->model_user_user->getUser($this->user->getId()); + + if ($user_info) { + $data['firstname'] = $user_info['firstname']; + $data['lastname'] = $user_info['lastname']; + $data['username'] = $user_info['username']; + $data['user_group'] = $user_info['user_group']; + + if (is_file(DIR_IMAGE . $user_info['image'])) { + $data['image'] = $this->model_tool_image->resize($user_info['image'], 45, 45); + } else { + $data['image'] = $this->model_tool_image->resize('profile.png', 45, 45); + } + } else { + $data['firstname'] = ''; + $data['lastname'] = ''; + $data['user_group'] = ''; + $data['image'] = ''; + } + + // Online Stores + $data['stores'] = array(); + + $data['stores'][] = array( + 'name' => $this->config->get('config_name'), + 'href' => HTTP_CATALOG + ); + + $this->load->model('setting/store'); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'name' => $result['name'], + 'href' => $result['url'] + ); + } + } + + return $this->load->view('common/header', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/login.php b/public/admin/controller/common/login.php new file mode 100644 index 0000000..0b84158 --- /dev/null +++ b/public/admin/controller/common/login.php @@ -0,0 +1,92 @@ +<?php +class ControllerCommonLogin extends Controller { + private $error = array(); + + public function index() { + $this->load->language('common/login'); + + $this->document->setTitle($this->language->get('heading_title')); + + if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { + $this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->session->data['user_token'] = token(32); + + if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], HTTP_SERVER) === 0 || strpos($this->request->post['redirect'], HTTPS_SERVER) === 0)) { + $this->response->redirect($this->request->post['redirect'] . '&user_token=' . $this->session->data['user_token']); + } else { + $this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + if ((isset($this->session->data['user_token']) && !isset($this->request->get['user_token'])) || ((isset($this->request->get['user_token']) && (isset($this->session->data['user_token']) && ($this->request->get['user_token'] != $this->session->data['user_token']))))) { + $this->error['warning'] = $this->language->get('error_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'] = ''; + } + + $data['action'] = $this->url->link('common/login', '', true); + + if (isset($this->request->post['username'])) { + $data['username'] = $this->request->post['username']; + } else { + $data['username'] = ''; + } + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->get['route'])) { + $route = $this->request->get['route']; + + unset($this->request->get['route']); + unset($this->request->get['user_token']); + + $url = ''; + + if ($this->request->get) { + $url .= http_build_query($this->request->get); + } + + $data['redirect'] = $this->url->link($route, $url, true); + } else { + $data['redirect'] = ''; + } + + if ($this->config->get('config_password')) { + $data['forgotten'] = $this->url->link('common/forgotten', '', true); + } else { + $data['forgotten'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('common/login', $data)); + } + + protected function validate() { + if (!isset($this->request->post['username']) || !isset($this->request->post['password']) || !$this->user->login($this->request->post['username'], html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'))) { + $this->error['warning'] = $this->language->get('error_login'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/common/logout.php b/public/admin/controller/common/logout.php new file mode 100644 index 0000000..d12ddf1 --- /dev/null +++ b/public/admin/controller/common/logout.php @@ -0,0 +1,10 @@ +<?php +class ControllerCommonLogout extends Controller { + public function index() { + $this->user->logout(); + + unset($this->session->data['user_token']); + + $this->response->redirect($this->url->link('common/login', '', true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/profile.php b/public/admin/controller/common/profile.php new file mode 100644 index 0000000..45c63c1 --- /dev/null +++ b/public/admin/controller/common/profile.php @@ -0,0 +1,211 @@ +<?php +class ControllerCommonProfile extends Controller { + private $error = array(); + + public function index() { + $this->load->language('common/profile'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $user_data = array_merge($this->request->post, array( + 'user_group_id' => $this->user->getGroupId(), + 'status' => 1, + )); + + $this->model_user_user->editUser($this->user->getId(), $user_data); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['confirm'])) { + $data['error_confirm'] = $this->error['confirm']; + } else { + $data['error_confirm'] = ''; + } + + 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'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->request->server['REQUEST_METHOD'] != 'POST') { + $user_info = $this->model_user_user->getUser($this->user->getId()); + } + + if (isset($this->request->post['username'])) { + $data['username'] = $this->request->post['username']; + } elseif (!empty($user_info)) { + $data['username'] = $user_info['username']; + } else { + $data['username'] = ''; + } + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->post['confirm'])) { + $data['confirm'] = $this->request->post['confirm']; + } else { + $data['confirm'] = ''; + } + + if (isset($this->request->post['firstname'])) { + $data['firstname'] = $this->request->post['firstname']; + } elseif (!empty($user_info)) { + $data['firstname'] = $user_info['firstname']; + } else { + $data['firstname'] = ''; + } + + if (isset($this->request->post['lastname'])) { + $data['lastname'] = $this->request->post['lastname']; + } elseif (!empty($user_info)) { + $data['lastname'] = $user_info['lastname']; + } else { + $data['lastname'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } elseif (!empty($user_info)) { + $data['email'] = $user_info['email']; + } else { + $data['email'] = ''; + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($user_info)) { + $data['image'] = $user_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($user_info) && $user_info['image'] && is_file(DIR_IMAGE . $user_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($user_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('common/profile', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'common/profile')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['username']) < 3) || (utf8_strlen($this->request->post['username']) > 20)) { + $this->error['username'] = $this->language->get('error_username'); + } + + $user_info = $this->model_user_user->getUserByUsername($this->request->post['username']); + + if ($user_info && ($this->user->getId() != $user_info['user_id'])) { + $this->error['warning'] = $this->language->get('error_exists_username'); + } + + 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) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + $user_info = $this->model_user_user->getUserByEmail($this->request->post['email']); + + if ($user_info && ($this->user->getId() != $user_info['user_id'])) { + $this->error['warning'] = $this->language->get('error_exists_email'); + } + + if ($this->request->post['password']) { + if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { + $this->error['password'] = $this->language->get('error_password'); + } + + if ($this->request->post['password'] != $this->request->post['confirm']) { + $this->error['confirm'] = $this->language->get('error_confirm'); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/reset.php b/public/admin/controller/common/reset.php new file mode 100644 index 0000000..e8248b4 --- /dev/null +++ b/public/admin/controller/common/reset.php @@ -0,0 +1,101 @@ +<?php +class ControllerCommonReset extends Controller { + private $error = array(); + + public function index() { + if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) { + $this->response->redirect($this->url->link('common/dashboard', '', true)); + } + + if (!$this->config->get('config_password')) { + $this->response->redirect($this->url->link('common/login', '', true)); + } + + if (isset($this->request->get['code'])) { + $code = $this->request->get['code']; + } else { + $code = ''; + } + + $this->load->model('user/user'); + + $user_info = $this->model_user_user->getUserByCode($code); + + if ($user_info) { + $this->load->language('common/reset'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('common/login', '', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', '', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('common/reset', '', true) + ); + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['confirm'])) { + $data['error_confirm'] = $this->error['confirm']; + } else { + $data['error_confirm'] = ''; + } + + $data['action'] = $this->url->link('common/reset', 'code=' . $code, true); + + $data['cancel'] = $this->url->link('common/login', '', true); + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->post['confirm'])) { + $data['confirm'] = $this->request->post['confirm']; + } else { + $data['confirm'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('common/reset', $data)); + } else { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSettingValue('config', 'config_password', '0'); + + return new Action('common/login'); + } + } + + protected function validate() { + if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { + $this->error['password'] = $this->language->get('error_password'); + } + + if ($this->request->post['confirm'] != $this->request->post['password']) { + $this->error['confirm'] = $this->language->get('error_confirm'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/common/security.php b/public/admin/controller/common/security.php new file mode 100644 index 0000000..07cfb9f --- /dev/null +++ b/public/admin/controller/common/security.php @@ -0,0 +1,143 @@ +<?php +class ControllerCommonSecurity extends Controller { + public function index() { + $this->load->language('common/security'); + + $data['text_instruction'] = $this->language->get('text_instruction'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['storage'] = DIR_SYSTEM . 'storage/'; + + $path = ''; + + $data['paths'] = array(); + + $parts = explode('/', str_replace('\\', '/', rtrim(DIR_SYSTEM, '/'))); + + foreach ($parts as $part) { + $path .= $part . '/'; + + $data['paths'][] = $path; + } + + rsort($data['paths']); + + $data['document_root'] = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../') . '/'); + + return $this->load->view('common/security', $data); + } + + public function move() { + $this->load->language('common/security'); + + $json = array(); + + if ($this->request->post['path']) { + $path = $this->request->post['path']; + } else { + $path = ''; + } + + if ($this->request->post['directory']) { + $directory = $this->request->post['directory']; + } else { + $directory = ''; + } + + if (!$this->user->hasPermission('modify', 'common/developer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + if (DIR_STORAGE != DIR_SYSTEM . 'storage/') { + $data['error'] = $this->language->get('error_path'); + } + + if (!$path || str_replace('\\', '/', realpath($path)) . '/' != str_replace('\\', '/', substr(DIR_SYSTEM, 0, strlen($path)))) { + $json['error'] = $this->language->get('error_path'); + } + + if (!$directory || !preg_match('/^[a-zA-Z0-9_-]+$/', $directory)) { + $json['error'] = $this->language->get('error_directory'); + } + + if (is_dir($path . $directory)) { + $json['error'] = $this->language->get('error_exists'); + } + + if (!is_writable(realpath(DIR_APPLICATION . '/../') . '/config.php') || !is_writable(DIR_APPLICATION . 'config.php')) { + $json['error'] = $this->language->get('error_writable'); + } + + if (!$json) { + $files = array(); + + // Make path into an array + $source = array(DIR_SYSTEM . 'storage/'); + + // While the path array is still populated keep looping through + while (count($source) != 0) { + $next = array_shift($source); + + foreach (glob($next) as $file) { + // If directory add to path array + if (is_dir($file)) { + $source[] = $file . '/*'; + } + + // Add the file to the files to be deleted array + $files[] = $file; + } + } + + // Create the new storage folder + if (!is_dir($path . $directory)) { + mkdir($path . $directory, 0777); + } + + // Copy the + foreach ($files as $file) { + $destination = $path . $directory . substr($file, strlen(DIR_SYSTEM . 'storage/')); + + if (is_dir($file) && !is_dir($destination)) { + mkdir($destination, 0777); + } + + if (is_file($file)) { + copy($file, $destination); + } + } + + // Modify the config files + $files = array( + DIR_APPLICATION . 'config.php', + realpath(DIR_APPLICATION . '/../') . '/config.php' + ); + + foreach ($files as $file) { + $output = ''; + + $lines = file($file); + + foreach ($lines as $line_id => $line) { + if (strpos($line, 'define(\'DIR_STORAGE') !== false) { + $output .= 'define(\'DIR_STORAGE\', \'' . $path . $directory . '/\');' . "\n"; + } else { + $output .= $line; + } + } + + $file = fopen($file, 'w'); + + fwrite($file, $output); + + fclose($file); + } + + $json['success'] = $this->language->get('text_success'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/customer/custom_field.php b/public/admin/controller/customer/custom_field.php new file mode 100644 index 0000000..54703ff --- /dev/null +++ b/public/admin/controller/customer/custom_field.php @@ -0,0 +1,498 @@ +<?php +class ControllerCustomerCustomField extends Controller { + private $error = array(); + + public function index() { + $this->load->language('customer/custom_field'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/custom_field'); + + $this->getList(); + } + + public function add() { + $this->load->language('customer/custom_field'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/custom_field'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_custom_field->addCustomField($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('customer/custom_field'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/custom_field'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_custom_field->editCustomField($this->request->get['custom_field_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('customer/custom_field'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/custom_field'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $custom_field_id) { + $this->model_customer_custom_field->deleteCustomField($custom_field_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'cfd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('customer/custom_field/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('customer/custom_field/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['custom_fields'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $custom_field_total = $this->model_customer_custom_field->getTotalCustomFields(); + + $results = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($results as $result) { + $type = ''; + + switch ($result['type']) { + case 'select': + $type = $this->language->get('text_select'); + break; + case 'radio': + $type = $this->language->get('text_radio'); + break; + case 'checkbox': + $type = $this->language->get('text_checkbox'); + break; + case 'input': + $type = $this->language->get('text_input'); + break; + case 'text': + $type = $this->language->get('text_text'); + break; + case 'textarea': + $type = $this->language->get('text_textarea'); + break; + case 'file': + $type = $this->language->get('text_file'); + break; + case 'date': + $type = $this->language->get('text_date'); + break; + case 'datetime': + $type = $this->language->get('text_datetime'); + break; + case 'time': + $type = $this->language->get('text_time'); + break; + } + + $data['custom_fields'][] = array( + 'custom_field_id' => $result['custom_field_id'], + 'name' => $result['name'], + 'location' => $this->language->get('text_' . $result['location']), + 'type' => $type, + 'status' => $result['status'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . '&sort=cfd.name' . $url, true); + $data['sort_location'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.location' . $url, true); + $data['sort_type'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.type' . $url, true); + $data['sort_status'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.status' . $url, true); + $data['sort_sort_order'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.sort_order' . $url, true); + + $url = ''; + + 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 = $custom_field_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($custom_field_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($custom_field_total - $this->config->get('config_limit_admin'))) ? $custom_field_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $custom_field_total, ceil($custom_field_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/custom_field_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['custom_field_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['custom_field_value'])) { + $data['error_custom_field_value'] = $this->error['custom_field_value']; + } else { + $data['error_custom_field_value'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['custom_field_id'])) { + $data['action'] = $this->url->link('customer/custom_field/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $this->request->get['custom_field_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['custom_field_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $custom_field_info = $this->model_customer_custom_field->getCustomField($this->request->get['custom_field_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['custom_field_description'])) { + $data['custom_field_description'] = $this->request->post['custom_field_description']; + } elseif (isset($this->request->get['custom_field_id'])) { + $data['custom_field_description'] = $this->model_customer_custom_field->getCustomFieldDescriptions($this->request->get['custom_field_id']); + } else { + $data['custom_field_description'] = array(); + } + + if (isset($this->request->post['location'])) { + $data['location'] = $this->request->post['location']; + } elseif (!empty($custom_field_info)) { + $data['location'] = $custom_field_info['location']; + } else { + $data['location'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } elseif (!empty($custom_field_info)) { + $data['type'] = $custom_field_info['type']; + } else { + $data['type'] = ''; + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($custom_field_info)) { + $data['value'] = $custom_field_info['value']; + } else { + $data['value'] = ''; + } + + if (isset($this->request->post['validation'])) { + $data['validation'] = $this->request->post['validation']; + } elseif (!empty($custom_field_info)) { + $data['validation'] = $custom_field_info['validation']; + } else { + $data['validation'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($custom_field_info)) { + $data['status'] = $custom_field_info['status']; + } else { + $data['status'] = ''; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($custom_field_info)) { + $data['sort_order'] = $custom_field_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + if (isset($this->request->post['custom_field_value'])) { + $custom_field_values = $this->request->post['custom_field_value']; + } elseif (isset($this->request->get['custom_field_id'])) { + $custom_field_values = $this->model_customer_custom_field->getCustomFieldValueDescriptions($this->request->get['custom_field_id']); + } else { + $custom_field_values = array(); + } + + $data['custom_field_values'] = array(); + + foreach ($custom_field_values as $custom_field_value) { + $data['custom_field_values'][] = array( + 'custom_field_value_id' => $custom_field_value['custom_field_value_id'], + 'custom_field_value_description' => $custom_field_value['custom_field_value_description'], + 'sort_order' => $custom_field_value['sort_order'] + ); + } + + if (isset($this->request->post['custom_field_customer_group'])) { + $custom_field_customer_groups = $this->request->post['custom_field_customer_group']; + } elseif (isset($this->request->get['custom_field_id'])) { + $custom_field_customer_groups = $this->model_customer_custom_field->getCustomFieldCustomerGroups($this->request->get['custom_field_id']); + } else { + $custom_field_customer_groups = array(); + } + + $data['custom_field_customer_group'] = array(); + + foreach ($custom_field_customer_groups as $custom_field_customer_group) { + $data['custom_field_customer_group'][] = $custom_field_customer_group['customer_group_id']; + } + + $data['custom_field_required'] = array(); + + foreach ($custom_field_customer_groups as $custom_field_customer_group) { + if ($custom_field_customer_group['required']) { + $data['custom_field_required'][] = $custom_field_customer_group['customer_group_id']; + } + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/custom_field_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'customer/custom_field')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['custom_field_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 128)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + if (($this->request->post['type'] == 'select' || $this->request->post['type'] == 'radio' || $this->request->post['type'] == 'checkbox')) { + if (!isset($this->request->post['custom_field_value'])) { + $this->error['warning'] = $this->language->get('error_type'); + } + + if (isset($this->request->post['custom_field_value'])) { + foreach ($this->request->post['custom_field_value'] as $custom_field_value_id => $custom_field_value) { + foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) { + if ((utf8_strlen($custom_field_value_description['name']) < 1) || (utf8_strlen($custom_field_value_description['name']) > 128)) { + $this->error['custom_field_value'][$custom_field_value_id][$language_id] = $this->language->get('error_custom_value'); + } + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'customer/custom_field')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/customer/customer.php b/public/admin/controller/customer/customer.php new file mode 100644 index 0000000..07617ca --- /dev/null +++ b/public/admin/controller/customer/customer.php @@ -0,0 +1,1490 @@ +<?php +class ControllerCustomerCustomer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('customer/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer'); + + $this->getList(); + } + + public function add() { + $this->load->language('customer/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_customer->addCustomer($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('customer/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_customer->editCustomer($this->request->get['customer_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('customer/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $customer_id) { + $this->model_customer_customer->deleteCustomer($customer_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function unlock() { + $this->load->language('customer/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer'); + + if (isset($this->request->get['email']) && $this->validateUnlock()) { + $this->model_customer_customer->deleteLoginAttempts($this->request->get['email']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_email'])) { + $filter_email = $this->request->get['filter_email']; + } else { + $filter_email = ''; + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $filter_customer_group_id = $this->request->get['filter_customer_group_id']; + } else { + $filter_customer_group_id = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('customer/customer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('customer/customer/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('setting/store'); + + $stores = $this->model_setting_store->getStores(); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_email' => $filter_email, + 'filter_customer_group_id' => $filter_customer_group_id, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'filter_ip' => $filter_ip, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_customer_customer->getTotalCustomers($filter_data); + + $results = $this->model_customer_customer->getCustomers($filter_data); + + foreach ($results as $result) { + $login_info = $this->model_customer_customer->getTotalLoginAttempts($result['email']); + + if ($login_info && $login_info['total'] >= $this->config->get('config_login_attempts')) { + $unlock = $this->url->link('customer/customer/unlock', 'user_token=' . $this->session->data['user_token'] . '&email=' . $result['email'] . $url, true); + } else { + $unlock = ''; + } + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'href' => $this->url->link('customer/customer/login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=0', true) + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'href' => $this->url->link('customer/customer/login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=' . $result['store_id'], true) + ); + } + + $data['customers'][] = array( + 'customer_id' => $result['customer_id'], + 'name' => $result['name'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'unlock' => $unlock, + 'store' => $store_data, + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_email'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.email' . $url, true); + $data['sort_customer_group'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=customer_group' . $url, true); + $data['sort_status'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.status' . $url, true); + $data['sort_ip'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.ip' . $url, true); + $data['sort_date_added'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_name'] = $filter_name; + $data['filter_email'] = $filter_email; + $data['filter_customer_group_id'] = $filter_customer_group_id; + $data['filter_status'] = $filter_status; + $data['filter_ip'] = $filter_ip; + $data['filter_date_added'] = $filter_date_added; + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/customer_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['customer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['customer_id'])) { + $data['customer_id'] = $this->request->get['customer_id']; + } else { + $data['customer_id'] = 0; + } + + 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['cheque'])) { + $data['error_cheque'] = $this->error['cheque']; + } else { + $data['error_cheque'] = ''; + } + + if (isset($this->error['paypal'])) { + $data['error_paypal'] = $this->error['paypal']; + } else { + $data['error_paypal'] = ''; + } + + if (isset($this->error['bank_account_name'])) { + $data['error_bank_account_name'] = $this->error['bank_account_name']; + } else { + $data['error_bank_account_name'] = ''; + } + + if (isset($this->error['bank_account_number'])) { + $data['error_bank_account_number'] = $this->error['bank_account_number']; + } else { + $data['error_bank_account_number'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['confirm'])) { + $data['error_confirm'] = $this->error['confirm']; + } else { + $data['error_confirm'] = ''; + } + + if (isset($this->error['custom_field'])) { + $data['error_custom_field'] = $this->error['custom_field']; + } else { + $data['error_custom_field'] = array(); + } + + if (isset($this->error['address'])) { + $data['error_address'] = $this->error['address']; + } else { + $data['error_address'] = array(); + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['customer_id'])) { + $data['action'] = $this->url->link('customer/customer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['customer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $customer_info = $this->model_customer_customer->getCustomer($this->request->get['customer_id']); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['customer_group_id'])) { + $data['customer_group_id'] = $this->request->post['customer_group_id']; + } elseif (!empty($customer_info)) { + $data['customer_group_id'] = $customer_info['customer_group_id']; + } else { + $data['customer_group_id'] = $this->config->get('config_customer_group_id'); + } + + if (isset($this->request->post['firstname'])) { + $data['firstname'] = $this->request->post['firstname']; + } elseif (!empty($customer_info)) { + $data['firstname'] = $customer_info['firstname']; + } else { + $data['firstname'] = ''; + } + + if (isset($this->request->post['lastname'])) { + $data['lastname'] = $this->request->post['lastname']; + } elseif (!empty($customer_info)) { + $data['lastname'] = $customer_info['lastname']; + } else { + $data['lastname'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } elseif (!empty($customer_info)) { + $data['email'] = $customer_info['email']; + } else { + $data['email'] = ''; + } + + if (isset($this->request->post['telephone'])) { + $data['telephone'] = $this->request->post['telephone']; + } elseif (!empty($customer_info)) { + $data['telephone'] = $customer_info['telephone']; + } else { + $data['telephone'] = ''; + } + + // Custom Fields + $this->load->model('customer/custom_field'); + + $data['custom_fields'] = array(); + + $filter_data = array( + 'sort' => 'cf.sort_order', + 'order' => 'ASC' + ); + + $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($custom_fields as $custom_field) { + $data['custom_fields'][] = array( + 'custom_field_id' => $custom_field['custom_field_id'], + 'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']), + 'name' => $custom_field['name'], + 'value' => $custom_field['value'], + 'type' => $custom_field['type'], + 'location' => $custom_field['location'], + 'sort_order' => $custom_field['sort_order'] + ); + } + + if (isset($this->request->post['custom_field'])) { + $data['account_custom_field'] = $this->request->post['custom_field']; + } elseif (!empty($customer_info)) { + $data['account_custom_field'] = json_decode($customer_info['custom_field'], true); + } else { + $data['account_custom_field'] = array(); + } + + if (isset($this->request->post['newsletter'])) { + $data['newsletter'] = $this->request->post['newsletter']; + } elseif (!empty($customer_info)) { + $data['newsletter'] = $customer_info['newsletter']; + } else { + $data['newsletter'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($customer_info)) { + $data['status'] = $customer_info['status']; + } else { + $data['status'] = true; + } + + if (isset($this->request->post['safe'])) { + $data['safe'] = $this->request->post['safe']; + } elseif (!empty($customer_info)) { + $data['safe'] = $customer_info['safe']; + } else { + $data['safe'] = 0; + } + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->post['confirm'])) { + $data['confirm'] = $this->request->post['confirm']; + } else { + $data['confirm'] = ''; + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + if (isset($this->request->post['address'])) { + $data['addresses'] = $this->request->post['address']; + } elseif (isset($this->request->get['customer_id'])) { + $data['addresses'] = $this->model_customer_customer->getAddresses($this->request->get['customer_id']); + } else { + $data['addresses'] = array(); + } + + if (isset($this->request->post['address_id'])) { + $data['address_id'] = $this->request->post['address_id']; + } elseif (!empty($customer_info)) { + $data['address_id'] = $customer_info['address_id']; + } else { + $data['address_id'] = ''; + } + + // Affliate + if (isset($this->request->get['customer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $affiliate_info = $this->model_customer_customer->getAffiliate($this->request->get['customer_id']); + } + + if (isset($this->request->post['affiliate'])) { + $data['affiliate'] = $this->request->post['affiliate']; + } elseif (!empty($affiliate_info)) { + $data['affiliate'] = $affiliate_info['status']; + } else { + $data['affiliate'] = ''; + } + + if (isset($this->request->post['company'])) { + $data['company'] = $this->request->post['company']; + } elseif (!empty($affiliate_info)) { + $data['company'] = $affiliate_info['company']; + } else { + $data['company'] = ''; + } + + if (isset($this->request->post['website'])) { + $data['website'] = $this->request->post['website']; + } elseif (!empty($affiliate_info)) { + $data['website'] = $affiliate_info['website']; + } else { + $data['website'] = ''; + } + + if (isset($this->request->post['tracking'])) { + $data['tracking'] = $this->request->post['tracking']; + } elseif (!empty($affiliate_info)) { + $data['tracking'] = $affiliate_info['tracking']; + } else { + $data['tracking'] = ''; + } + + if (isset($this->request->post['commission'])) { + $data['commission'] = $this->request->post['commission']; + } elseif (!empty($affiliate_info)) { + $data['commission'] = $affiliate_info['commission']; + } else { + $data['commission'] = $this->config->get('config_affiliate_commission'); + } + + if (isset($this->request->post['tax'])) { + $data['tax'] = $this->request->post['tax']; + } elseif (!empty($affiliate_info)) { + $data['tax'] = $affiliate_info['tax']; + } else { + $data['tax'] = ''; + } + + if (isset($this->request->post['payment'])) { + $data['payment'] = $this->request->post['payment']; + } elseif (!empty($affiliate_info)) { + $data['payment'] = $affiliate_info['payment']; + } else { + $data['payment'] = 'cheque'; + } + + if (isset($this->request->post['cheque'])) { + $data['cheque'] = $this->request->post['cheque']; + } elseif (!empty($affiliate_info)) { + $data['cheque'] = $affiliate_info['cheque']; + } else { + $data['cheque'] = ''; + } + + if (isset($this->request->post['paypal'])) { + $data['paypal'] = $this->request->post['paypal']; + } elseif (!empty($affiliate_info)) { + $data['paypal'] = $affiliate_info['paypal']; + } else { + $data['paypal'] = ''; + } + + if (isset($this->request->post['bank_name'])) { + $data['bank_name'] = $this->request->post['bank_name']; + } elseif (!empty($affiliate_info)) { + $data['bank_name'] = $affiliate_info['bank_name']; + } else { + $data['bank_name'] = ''; + } + + if (isset($this->request->post['bank_branch_number'])) { + $data['bank_branch_number'] = $this->request->post['bank_branch_number']; + } elseif (!empty($affiliate_info)) { + $data['bank_branch_number'] = $affiliate_info['bank_branch_number']; + } else { + $data['bank_branch_number'] = ''; + } + + if (isset($this->request->post['bank_swift_code'])) { + $data['bank_swift_code'] = $this->request->post['bank_swift_code']; + } elseif (!empty($affiliate_info)) { + $data['bank_swift_code'] = $affiliate_info['bank_swift_code']; + } else { + $data['bank_swift_code'] = ''; + } + + if (isset($this->request->post['bank_account_name'])) { + $data['bank_account_name'] = $this->request->post['bank_account_name']; + } elseif (!empty($affiliate_info)) { + $data['bank_account_name'] = $affiliate_info['bank_account_name']; + } else { + $data['bank_account_name'] = ''; + } + + if (isset($this->request->post['bank_account_number'])) { + $data['bank_account_number'] = $this->request->post['bank_account_number']; + } elseif (!empty($affiliate_info)) { + $data['bank_account_number'] = $affiliate_info['bank_account_number']; + } else { + $data['bank_account_number'] = ''; + } + + if (isset($this->request->post['custom_field'])) { + $data['affiliate_custom_field'] = $this->request->post['custom_field']; + } elseif (!empty($affiliate_info)) { + $data['affiliate_custom_field'] = json_decode($affiliate_info['custom_field'], true); + } else { + $data['affiliate_custom_field'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/customer_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'customer/customer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { + $this->error['firstname'] = $this->language->get('error_firstname'); + } + + if ((utf8_strlen($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) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + $customer_info = $this->model_customer_customer->getCustomerByEmail($this->request->post['email']); + + if (!isset($this->request->get['customer_id'])) { + if ($customer_info) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } else { + if ($customer_info && ($this->request->get['customer_id'] != $customer_info['customer_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + // Custom field validation + $this->load->model('customer/custom_field'); + + $custom_fields = $this->model_customer_custom_field->getCustomFields(array('filter_customer_group_id' => $this->request->post['customer_group_id'])); + + foreach ($custom_fields as $custom_field) { + if (($custom_field['location'] == 'account') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { + $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } elseif (($custom_field['location'] == 'account') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { + $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } + } + + if ($this->request->post['password'] || (!isset($this->request->get['customer_id']))) { + if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { + $this->error['password'] = $this->language->get('error_password'); + } + + if ($this->request->post['password'] != $this->request->post['confirm']) { + $this->error['confirm'] = $this->language->get('error_confirm'); + } + } + + if (isset($this->request->post['address'])) { + foreach ($this->request->post['address'] as $key => $value) { + if ((utf8_strlen($value['firstname']) < 1) || (utf8_strlen($value['firstname']) > 32)) { + $this->error['address'][$key]['firstname'] = $this->language->get('error_firstname'); + } + + if ((utf8_strlen($value['lastname']) < 1) || (utf8_strlen($value['lastname']) > 32)) { + $this->error['address'][$key]['lastname'] = $this->language->get('error_lastname'); + } + + if ((utf8_strlen($value['address_1']) < 3) || (utf8_strlen($value['address_1']) > 128)) { + $this->error['address'][$key]['address_1'] = $this->language->get('error_address_1'); + } + + if ((utf8_strlen($value['city']) < 2) || (utf8_strlen($value['city']) > 128)) { + $this->error['address'][$key]['city'] = $this->language->get('error_city'); + } + + $this->load->model('localisation/country'); + + $country_info = $this->model_localisation_country->getCountry($value['country_id']); + + if ($country_info && $country_info['postcode_required'] && (utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10)) { + $this->error['address'][$key]['postcode'] = $this->language->get('error_postcode'); + } + + if ($value['country_id'] == '') { + $this->error['address'][$key]['country'] = $this->language->get('error_country'); + } + + if (!isset($value['zone_id']) || $value['zone_id'] == '') { + $this->error['address'][$key]['zone'] = $this->language->get('error_zone'); + } + + foreach ($custom_fields as $custom_field) { + if (($custom_field['location'] == 'address') && $custom_field['required'] && empty($value['custom_field'][$custom_field['custom_field_id']])) { + $this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } elseif (($custom_field['location'] == 'address') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($value['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { + $this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } + } + } + } + + if ($this->request->post['affiliate']) { + if ($this->request->post['payment'] == 'cheque') { + if ($this->request->post['cheque'] == '') { + $this->error['cheque'] = $this->language->get('error_cheque'); + } + } elseif ($this->request->post['payment'] == 'paypal') { + if ((utf8_strlen($this->request->post['paypal']) > 96) || !filter_var($this->request->post['paypal'], FILTER_VALIDATE_EMAIL)) { + $this->error['paypal'] = $this->language->get('error_paypal'); + } + } elseif ($this->request->post['payment'] == 'bank') { + if ($this->request->post['bank_account_name'] == '') { + $this->error['bank_account_name'] = $this->language->get('error_bank_account_name'); + } + + if ($this->request->post['bank_account_number'] == '') { + $this->error['bank_account_number'] = $this->language->get('error_bank_account_number'); + } + } + + if (!$this->request->post['tracking']) { + $this->error['tracking'] = $this->language->get('error_tracking'); + } + + $affiliate_info = $this->model_customer_customer->getAffliateByTracking($this->request->post['tracking']); + + if (!isset($this->request->get['customer_id'])) { + if ($affiliate_info) { + $this->error['tracking'] = $this->language->get('error_tracking_exists'); + } + } else { + if ($affiliate_info && ($this->request->get['customer_id'] != $affiliate_info['customer_id'])) { + $this->error['tracking'] = $this->language->get('error_tracking_exists'); + } + } + + foreach ($custom_fields as $custom_field) { + if (($custom_field['location'] == 'affiliate') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { + $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } elseif (($custom_field['location'] == 'affiliate') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { + $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); + } + } + } + + 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', 'customer/customer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + protected function validateUnlock() { + if (!$this->user->hasPermission('modify', 'customer/customer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function login() { + if (isset($this->request->get['customer_id'])) { + $customer_id = $this->request->get['customer_id']; + } else { + $customer_id = 0; + } + + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($customer_id); + + if ($customer_info) { + // Create token to login with + $token = token(64); + + $this->model_customer_customer->editToken($customer_id, $token); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($store_id); + + if ($store_info) { + $this->response->redirect($store_info['url'] . 'index.php?route=account/login&token=' . $token); + } else { + $this->response->redirect(HTTP_CATALOG . 'index.php?route=account/login&token=' . $token); + } + } else { + $this->load->language('error/not_found'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('error/not_found', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('error/not_found', $data)); + } + } + + public function history() { + $this->load->language('customer/customer'); + + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_customer_customer->getHistories($this->request->get['customer_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'comment' => $result['comment'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_customer_customer->getTotalHistories($this->request->get['customer_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('customer/customer/history', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('customer/customer_history', $data)); + } + + public function addHistory() { + $this->load->language('customer/customer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'customer/customer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('customer/customer'); + + $this->model_customer_customer->addHistory($this->request->get['customer_id'], $this->request->post['comment']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function transaction() { + $this->load->language('customer/customer'); + + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['transactions'] = array(); + + $results = $this->model_customer_customer->getTransactions($this->request->get['customer_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['transactions'][] = array( + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), + 'description' => $result['description'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $data['balance'] = $this->currency->format($this->model_customer_customer->getTransactionTotal($this->request->get['customer_id']), $this->config->get('config_currency')); + + $transaction_total = $this->model_customer_customer->getTotalTransactions($this->request->get['customer_id']); + + $pagination = new Pagination(); + $pagination->total = $transaction_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('customer/customer/transaction', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($transaction_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($transaction_total - 10)) ? $transaction_total : ((($page - 1) * 10) + 10), $transaction_total, ceil($transaction_total / 10)); + + $this->response->setOutput($this->load->view('customer/customer_transaction', $data)); + } + + public function addTransaction() { + $this->load->language('customer/customer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'customer/customer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('customer/customer'); + + $this->model_customer_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function reward() { + $this->load->language('customer/customer'); + + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['rewards'] = array(); + + $results = $this->model_customer_customer->getRewards($this->request->get['customer_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['rewards'][] = array( + 'points' => $result['points'], + 'description' => $result['description'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $data['balance'] = $this->model_customer_customer->getRewardTotal($this->request->get['customer_id']); + + $reward_total = $this->model_customer_customer->getTotalRewards($this->request->get['customer_id']); + + $pagination = new Pagination(); + $pagination->total = $reward_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('customer/customer/reward', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($reward_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($reward_total - 10)) ? $reward_total : ((($page - 1) * 10) + 10), $reward_total, ceil($reward_total / 10)); + + $this->response->setOutput($this->load->view('customer/customer_reward', $data)); + } + + public function addReward() { + $this->load->language('customer/customer'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'customer/customer')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('customer/customer'); + + $this->model_customer_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function ip() { + $this->load->language('customer/customer'); + + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['ips'] = array(); + + $results = $this->model_customer_customer->getIps($this->request->get['customer_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['ips'][] = array( + 'ip' => $result['ip'], + 'total' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']), + 'date_added' => date('d/m/y', strtotime($result['date_added'])), + 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'], true) + ); + } + + $ip_total = $this->model_customer_customer->getTotalIps($this->request->get['customer_id']); + + $pagination = new Pagination(); + $pagination->total = $ip_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('customer/customer/ip', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($ip_total - 10)) ? $ip_total : ((($page - 1) * 10) + 10), $ip_total, ceil($ip_total / 10)); + + $this->response->setOutput($this->load->view('customer/customer_ip', $data)); + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_email'])) { + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_email'])) { + $filter_email = $this->request->get['filter_email']; + } else { + $filter_email = ''; + } + + if (isset($this->request->get['filter_affiliate'])) { + $filter_affiliate = $this->request->get['filter_affiliate']; + } else { + $filter_affiliate = ''; + } + + $this->load->model('customer/customer'); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_email' => $filter_email, + 'filter_affiliate' => $filter_affiliate, + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_customer_customer->getCustomers($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'customer_id' => $result['customer_id'], + 'customer_group_id' => $result['customer_group_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), + 'customer_group' => $result['customer_group'], + 'firstname' => $result['firstname'], + 'lastname' => $result['lastname'], + 'email' => $result['email'], + 'telephone' => $result['telephone'], + 'custom_field' => json_decode($result['custom_field'], true), + 'address' => $this->model_customer_customer->getAddresses($result['customer_id']) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function customfield() { + $json = array(); + + $this->load->model('customer/custom_field'); + + // Customer Group + if (isset($this->request->get['customer_group_id'])) { + $customer_group_id = $this->request->get['customer_group_id']; + } else { + $customer_group_id = $this->config->get('config_customer_group_id'); + } + + $custom_fields = $this->model_customer_custom_field->getCustomFields(array('filter_customer_group_id' => $customer_group_id)); + + foreach ($custom_fields as $custom_field) { + $json[] = array( + 'custom_field_id' => $custom_field['custom_field_id'], + 'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function address() { + $json = array(); + + if (!empty($this->request->get['address_id'])) { + $this->load->model('customer/customer'); + + $json = $this->model_customer_customer->getAddress($this->request->get['address_id']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/customer/customer_approval.php b/public/admin/controller/customer/customer_approval.php new file mode 100644 index 0000000..3d083db --- /dev/null +++ b/public/admin/controller/customer/customer_approval.php @@ -0,0 +1,246 @@ +<?php +class ControllerCustomerCustomerApproval extends Controller { + public function index() { + $this->load->language('customer/customer_approval'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_email'])) { + $filter_email = $this->request->get['filter_email']; + } else { + $filter_email = ''; + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $filter_customer_group_id = $this->request->get['filter_customer_group_id']; + } else { + $filter_customer_group_id = ''; + } + + if (isset($this->request->get['filter_type'])) { + $filter_type = $this->request->get['filter_type']; + } else { + $filter_type = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_type'])) { + $url .= '&filter_type=' . $this->request->get['filter_type']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/customer_approval', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['filter_name'] = $filter_name; + $data['filter_email'] = $filter_email; + $data['filter_customer_group_id'] = $filter_customer_group_id; + $data['filter_type'] = $filter_type; + $data['filter_date_added'] = $filter_date_added; + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/customer_approval', $data)); + } + + public function customer_approval() { + $this->load->language('customer/customer_approval'); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_email'])) { + $filter_email = $this->request->get['filter_email']; + } else { + $filter_email = ''; + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $filter_customer_group_id = $this->request->get['filter_customer_group_id']; + } else { + $filter_customer_group_id = ''; + } + + if (isset($this->request->get['filter_type'])) { + $filter_type = $this->request->get['filter_type']; + } else { + $filter_type = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['customer_approvals'] = array(); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_email' => $filter_email, + 'filter_customer_group_id' => $filter_customer_group_id, + 'filter_type' => $filter_type, + 'filter_date_added' => $filter_date_added, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $this->load->model('customer/customer_approval'); + + $customer_approval_total = $this->model_customer_customer_approval->getTotalCustomerApprovals($filter_data); + + $results = $this->model_customer_customer_approval->getCustomerApprovals($filter_data); + + foreach ($results as $result) { + $data['customer_approvals'][] = array( + 'customer_id' => $result['customer_id'], + 'name' => $result['name'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'type' => $this->language->get('text_' . $result['type']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'approve' => $this->url->link('customer/customer_approval/approve', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&type=' . $result['type'], true), + 'deny' => $this->url->link('customer/customer_approval/deny', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&type=' . $result['type'], true), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_email'])) { + $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer_group_id'])) { + $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; + } + + if (isset($this->request->get['filter_type'])) { + $url .= '&filter_type=' . $this->request->get['filter_type']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + $pagination = new Pagination(); + $pagination->total = $customer_approval_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('customer/customer_approval/customer_approval', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_approval_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_approval_total - $this->config->get('config_limit_admin'))) ? $customer_approval_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_approval_total, ceil($customer_approval_total / $this->config->get('config_limit_admin'))); + + $this->response->setOutput($this->load->view('customer/customer_approval_list', $data)); + } + + public function approve() { + $this->load->language('customer/customer_approval'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'customer/customer_approval')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('customer/customer_approval'); + + if ($this->request->get['type'] == 'customer') { + $this->model_customer_customer_approval->approveCustomer($this->request->get['customer_id']); + } elseif ($this->request->get['type'] == 'affiliate') { + $this->model_customer_customer_approval->approveAffiliate($this->request->get['customer_id']); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function deny() { + $this->load->language('customer/customer_approval'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'customer/customer_approval')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('customer/customer_approval'); + + if ($this->request->get['type'] == 'customer') { + $this->model_customer_customer_approval->denyCustomer($this->request->get['customer_id']); + } elseif ($this->request->get['type'] == 'affiliate') { + $this->model_customer_customer_approval->denyAffiliate($this->request->get['customer_id']); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/customer/customer_group.php b/public/admin/controller/customer/customer_group.php new file mode 100644 index 0000000..c446ead --- /dev/null +++ b/public/admin/controller/customer/customer_group.php @@ -0,0 +1,378 @@ +<?php +class ControllerCustomerCustomerGroup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('customer/customer_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer_group'); + + $this->getList(); + } + + public function add() { + $this->load->language('customer/customer_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_customer_group->addCustomerGroup($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('customer/customer_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_customer_customer_group->editCustomerGroup($this->request->get['customer_group_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('customer/customer_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('customer/customer_group'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $customer_group_id) { + $this->model_customer_customer_group->deleteCustomerGroup($customer_group_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'cgd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('customer/customer_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('customer/customer_group/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['customer_groups'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_group_total = $this->model_customer_customer_group->getTotalCustomerGroups(); + + $results = $this->model_customer_customer_group->getCustomerGroups($filter_data); + + foreach ($results as $result) { + $data['customer_groups'][] = array( + 'customer_group_id' => $result['customer_group_id'], + 'name' => $result['name'] . (($result['customer_group_id'] == $this->config->get('config_customer_group_id')) ? $this->language->get('text_default') : null), + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('customer/customer_group/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_group_id=' . $result['customer_group_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . '&sort=cgd.name' . $url, true); + $data['sort_sort_order'] = $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . '&sort=cg.sort_order' . $url, true); + + $url = ''; + + 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 = $customer_group_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_group_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_group_total - $this->config->get('config_limit_admin'))) ? $customer_group_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_group_total, ceil($customer_group_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/customer_group_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['customer_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['customer_group_id'])) { + $data['action'] = $this->url->link('customer/customer_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('customer/customer_group/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_group_id=' . $this->request->get['customer_group_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['customer_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $customer_group_info = $this->model_customer_customer_group->getCustomerGroup($this->request->get['customer_group_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['customer_group_description'])) { + $data['customer_group_description'] = $this->request->post['customer_group_description']; + } elseif (isset($this->request->get['customer_group_id'])) { + $data['customer_group_description'] = $this->model_customer_customer_group->getCustomerGroupDescriptions($this->request->get['customer_group_id']); + } else { + $data['customer_group_description'] = array(); + } + + if (isset($this->request->post['approval'])) { + $data['approval'] = $this->request->post['approval']; + } elseif (!empty($customer_group_info)) { + $data['approval'] = $customer_group_info['approval']; + } else { + $data['approval'] = ''; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($customer_group_info)) { + $data['sort_order'] = $customer_group_info['sort_order']; + } else { + $data['sort_order'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('customer/customer_group_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'customer/customer_group')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['customer_group_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'customer/customer_group')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('customer/customer'); + + foreach ($this->request->post['selected'] as $customer_group_id) { + if ($this->config->get('config_customer_group_id') == $customer_group_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByCustomerGroupId($customer_group_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $customer_total = $this->model_customer_customer->getTotalCustomersByCustomerGroupId($customer_group_id); + + if ($customer_total) { + $this->error['warning'] = sprintf($this->language->get('error_customer'), $customer_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/design/banner.php b/public/admin/controller/design/banner.php new file mode 100644 index 0000000..624a419 --- /dev/null +++ b/public/admin/controller/design/banner.php @@ -0,0 +1,399 @@ +<?php +class ControllerDesignBanner extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_banner->addBanner($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_banner->editBanner($this->request->get['banner_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $banner_id) { + $this->model_design_banner->deleteBanner($banner_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/banner/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/banner/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['banners'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $banner_total = $this->model_design_banner->getTotalBanners(); + + $results = $this->model_design_banner->getBanners($filter_data); + + foreach ($results as $result) { + $data['banners'][] = array( + 'banner_id' => $result['banner_id'], + 'name' => $result['name'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'edit' => $this->url->link('design/banner/edit', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $result['banner_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_status'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + + $url = ''; + + 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 = $banner_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($banner_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($banner_total - $this->config->get('config_limit_admin'))) ? $banner_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $banner_total, ceil($banner_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/banner_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['banner_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['banner_image'])) { + $data['error_banner_image'] = $this->error['banner_image']; + } else { + $data['error_banner_image'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['banner_id'])) { + $data['action'] = $this->url->link('design/banner/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/banner/edit', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $this->request->get['banner_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['banner_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $banner_info = $this->model_design_banner->getBanner($this->request->get['banner_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($banner_info)) { + $data['name'] = $banner_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($banner_info)) { + $data['status'] = $banner_info['status']; + } else { + $data['status'] = true; + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $this->load->model('tool/image'); + + if (isset($this->request->post['banner_image'])) { + $banner_images = $this->request->post['banner_image']; + } elseif (isset($this->request->get['banner_id'])) { + $banner_images = $this->model_design_banner->getBannerImages($this->request->get['banner_id']); + } else { + $banner_images = array(); + } + + $data['banner_images'] = array(); + + foreach ($banner_images as $key => $value) { + foreach ($value as $banner_image) { + if (is_file(DIR_IMAGE . $banner_image['image'])) { + $image = $banner_image['image']; + $thumb = $banner_image['image']; + } else { + $image = ''; + $thumb = 'no_image.png'; + } + + $data['banner_images'][$key][] = array( + 'title' => $banner_image['title'], + 'link' => $banner_image['link'], + 'image' => $image, + 'thumb' => $this->model_tool_image->resize($thumb, 100, 100), + 'sort_order' => $banner_image['sort_order'] + ); + } + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/banner_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (isset($this->request->post['banner_image'])) { + foreach ($this->request->post['banner_image'] as $language_id => $value) { + foreach ($value as $banner_image_id => $banner_image) { + if ((utf8_strlen($banner_image['title']) < 2) || (utf8_strlen($banner_image['title']) > 64)) { + $this->error['banner_image'][$language_id][$banner_image_id] = $this->language->get('error_title'); + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/design/layout.php b/public/admin/controller/design/layout.php new file mode 100644 index 0000000..90acbb3 --- /dev/null +++ b/public/admin/controller/design/layout.php @@ -0,0 +1,455 @@ +<?php +class ControllerDesignLayout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_layout->addLayout($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_layout->editLayout($this->request->get['layout_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $layout_id) { + $this->model_design_layout->deleteLayout($layout_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/layout/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['layouts'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $layout_total = $this->model_design_layout->getTotalLayouts(); + + $results = $this->model_design_layout->getLayouts($filter_data); + + foreach ($results as $result) { + $data['layouts'][] = array( + 'layout_id' => $result['layout_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $layout_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($layout_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($layout_total - $this->config->get('config_limit_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $layout_total, ceil($layout_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/layout_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['layout_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['layout_id'])) { + $data['action'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $this->request->get['layout_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['layout_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($layout_info)) { + $data['name'] = $layout_info['name']; + } else { + $data['name'] = ''; + } + + $this->load->model('setting/store'); + + $data['stores'] = $this->model_setting_store->getStores(); + + if (isset($this->request->post['layout_route'])) { + $data['layout_routes'] = $this->request->post['layout_route']; + } elseif (isset($this->request->get['layout_id'])) { + $data['layout_routes'] = $this->model_design_layout->getLayoutRoutes($this->request->get['layout_id']); + } else { + $data['layout_routes'] = array(); + } + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + $data['extensions'] = array(); + + // Get a list of installed modules + $extensions = $this->model_setting_extension->getInstalled('module'); + + // Add all the modules which have multiple settings for each module + foreach ($extensions as $code) { + $this->load->language('extension/module/' . $code, 'extension'); + + $module_data = array(); + + $modules = $this->model_setting_module->getModulesByCode($code); + + foreach ($modules as $module) { + $module_data[] = array( + 'name' => strip_tags($module['name']), + 'code' => $code . '.' . $module['module_id'] + ); + } + + if ($this->config->has('module_' . $code . '_status') || $module_data) { + $data['extensions'][] = array( + 'name' => strip_tags($this->language->get('extension')->get('heading_title')), + 'code' => $code, + 'module' => $module_data + ); + } + } + + // Modules layout + if (isset($this->request->post['layout_module'])) { + $layout_modules = $this->request->post['layout_module']; + } elseif (isset($this->request->get['layout_id'])) { + $layout_modules = $this->model_design_layout->getLayoutModules($this->request->get['layout_id']); + } else { + $layout_modules = array(); + } + + $data['layout_modules'] = array(); + + // Add all the modules which have multiple settings for each module + foreach ($layout_modules as $layout_module) { + $part = explode('.', $layout_module['code']); + + $this->load->language('extension/module/' . $part[0]); + + if (!isset($part[1])) { + $data['layout_modules'][] = array( + 'name' => strip_tags($this->language->get('heading_title')), + 'code' => $layout_module['code'], + 'edit' => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'], true), + 'position' => $layout_module['position'], + 'sort_order' => $layout_module['sort_order'] + ); + } else { + $module_info = $this->model_setting_module->getModule($part[1]); + + if ($module_info) { + $data['layout_modules'][] = array( + 'name' => strip_tags($module_info['name']), + 'code' => $layout_module['code'], + 'edit' => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[1], true), + 'position' => $layout_module['position'], + 'sort_order' => $layout_module['sort_order'] + ); + } + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/layout_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('catalog/product'); + $this->load->model('catalog/category'); + $this->load->model('catalog/information'); + + foreach ($this->request->post['selected'] as $layout_id) { + if ($this->config->get('config_layout_id') == $layout_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByLayoutId($layout_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $product_total = $this->model_catalog_product->getTotalProductsByLayoutId($layout_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + + $category_total = $this->model_catalog_category->getTotalCategoriesByLayoutId($layout_id); + + if ($category_total) { + $this->error['warning'] = sprintf($this->language->get('error_category'), $category_total); + } + + $information_total = $this->model_catalog_information->getTotalInformationsByLayoutId($layout_id); + + if ($information_total) { + $this->error['warning'] = sprintf($this->language->get('error_information'), $information_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/design/seo_url.php b/public/admin/controller/design/seo_url.php new file mode 100644 index 0000000..a00e566 --- /dev/null +++ b/public/admin/controller/design/seo_url.php @@ -0,0 +1,544 @@ +<?php +class ControllerDesignSeoUrl extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_seo_url->addSeoUrl($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_seo_url->editSeoUrl($this->request->get['seo_url_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $seo_url_id) { + $this->model_design_seo_url->deleteSeoUrl($seo_url_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_query'])) { + $filter_query = $this->request->get['filter_query']; + } else { + $filter_query = ''; + } + + if (isset($this->request->get['filter_keyword'])) { + $filter_keyword = $this->request->get['filter_keyword']; + } else { + $filter_keyword = ''; + } + + if (isset($this->request->get['filter_store_id'])) { + $filter_store_id = $this->request->get['filter_store_id']; + } else { + $filter_store_id = ''; + } + + if (isset($this->request->get['filter_language_id'])) { + $filter_language_id = $this->request->get['filter_language_id']; + } else { + $filter_language_id = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'keyword'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/seo_url/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/seo_url/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['seo_urls'] = array(); + + $filter_data = array( + 'filter_query' => $filter_query, + 'filter_keyword' => $filter_keyword, + 'filter_store_id' => $filter_store_id, + 'filter_language_id' => $filter_language_id, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $seo_url_total = $this->model_design_seo_url->getTotalSeoUrls($filter_data); + + $results = $this->model_design_seo_url->getSeoUrls($filter_data); + + foreach ($results as $result) { + $data['seo_urls'][] = array( + 'seo_url_id' => $result['seo_url_id'], + 'query' => $result['query'], + 'keyword' => $result['keyword'], + 'store' => $result['store_id'] ? $result['store'] : $this->language->get('text_default'), + 'language' => $result['language'], + 'edit' => $this->url->link('design/seo_url/edit', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $result['seo_url_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_query'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=query' . $url, true); + $data['sort_keyword'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url, true); + $data['sort_store'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url, true); + $data['sort_language'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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 = $seo_url_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($seo_url_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($seo_url_total - $this->config->get('config_limit_admin'))) ? $seo_url_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $seo_url_total, ceil($seo_url_total / $this->config->get('config_limit_admin'))); + + $data['filter_query'] = $filter_query; + $data['filter_keyword'] = $filter_keyword; + $data['filter_store_id'] = $filter_store_id; + $data['filter_language_id'] = $filter_language_id; + + $data['sort'] = $sort; + $data['order'] = $order; + + $this->load->model('setting/store'); + + $data['stores'] = $this->model_setting_store->getStores(); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/seo_url_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['seo_url_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['query'])) { + $data['error_query'] = $this->error['query']; + } else { + $data['error_query'] = ''; + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['seo_url_id'])) { + $data['action'] = $this->url->link('design/seo_url/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/seo_url/edit', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $this->request->get['seo_url_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['seo_url_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $seo_url_info = $this->model_design_seo_url->getSeoUrl($this->request->get['seo_url_id']); + } + + if (isset($this->request->post['query'])) { + $data['query'] = $this->request->post['query']; + } elseif (!empty($seo_url_info)) { + $data['query'] = $seo_url_info['query']; + } else { + $data['query'] = ''; + } + + if (isset($this->request->post['keyword'])) { + $data['keyword'] = $this->request->post['keyword']; + } elseif (!empty($seo_url_info)) { + $data['keyword'] = $seo_url_info['keyword']; + } else { + $data['keyword'] = ''; + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['store_id'])) { + $data['store_id'] = $this->request->post['store_id']; + } elseif (!empty($seo_url_info)) { + $data['store_id'] = $seo_url_info['store_id']; + } else { + $data['store_id'] = ''; + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['language_id'])) { + $data['language_id'] = $this->request->post['language_id']; + } elseif (!empty($seo_url_info)) { + $data['language_id'] = $seo_url_info['language_id']; + } else { + $data['language_id'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/seo_url_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/seo_url')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['query']) { + $this->error['query'] = $this->language->get('error_query'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($this->request->post['keyword']); + + foreach ($seo_urls as $seo_url) { + if ($seo_url['store_id'] == $this->request->post['store_id'] && $seo_url['query'] != $this->request->post['query']) { + $this->error['keyword'] = $this->language->get('error_exists'); + + break; + } + } + + if (!$this->request->post['keyword']) { + $this->error['keyword'] = $this->language->get('error_keyword'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/seo_url')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/design/theme.php b/public/admin/controller/design/theme.php new file mode 100644 index 0000000..839d03f --- /dev/null +++ b/public/admin/controller/design/theme.php @@ -0,0 +1,311 @@ +<?php +class ControllerDesignTheme extends Controller { + public function index() { + $this->load->language('design/theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['stores'] = array(); + + $this->load->model('setting/store'); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'store_id' => $result['store_id'], + 'name' => $result['name'] + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/theme', $data)); + } + + public function history() { + $this->load->language('design/theme'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $this->load->model('design/theme'); + $this->load->model('setting/store'); + + $history_total = $this->model_design_theme->getTotalThemes(); + + $results = $this->model_design_theme->getThemes(($page - 1) * 10, 10); + + foreach ($results as $result) { + $store_info = $this->model_setting_store->getStore($result['store_id']); + + if ($store_info) { + $store = $store_info['name']; + } else { + $store = ''; + } + + $data['histories'][] = array( + 'store_id' => $result['store_id'], + 'store' => ($result['store_id'] ? $store : $this->language->get('text_default')), + 'route' => $result['route'], + 'theme' => $result['theme'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('design/theme/template', 'user_token=' . $this->session->data['user_token'], true), + 'delete' => $this->url->link('design/theme/delete', 'user_token=' . $this->session->data['user_token'] . '&theme_id=' . $result['theme_id'], true) + ); + } + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('design/theme/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('design/theme_history', $data)); + } + + public function path() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + if (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/default/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view') { + $path_data = array(); + + // We grab the files from the default theme directory first as the custom themes drops back to the default theme if selected theme files can not be found. + $files = glob(rtrim(DIR_CATALOG . 'view/theme/{default,' . $theme . '}/template/' . $path, '/') . '/*', GLOB_BRACE); + + if ($files) { + foreach($files as $file) { + if (!in_array(basename($file), $path_data)) { + if (is_dir($file)) { + $json['directory'][] = array( + 'name' => basename($file), + 'path' => trim($path . '/' . basename($file), '/') + ); + } + + if (is_file($file)) { + $json['file'][] = array( + 'name' => basename($file), + 'path' => trim($path . '/' . basename($file), '/') + ); + } + + $path_data[] = basename($file); + } + } + } + } + + if (!empty($this->request->get['path'])) { + $json['back'] = array( + 'name' => $this->language->get('button_back'), + 'path' => urlencode(substr($path, 0, strrpos($path, '/'))), + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function template() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + $this->load->model('design/theme'); + + $theme_info = $this->model_design_theme->getTheme($store_id, $theme, $path); + + if ($theme_info) { + $json['code'] = html_entity_decode($theme_info['code']); + } elseif (is_file(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path); + } elseif (is_file(DIR_CATALOG . 'view/theme/default/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/default/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/default/template/' . $path); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function save() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + // Check user has permission + if (!$this->user->hasPermission('modify', 'design/theme')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (substr($path, -5) != '.twig') { + $json['error'] = $this->language->get('error_twig'); + } + + if (!$json) { + $this->load->model('design/theme'); + + $pos = strpos($path, '.'); + + $this->model_design_theme->editTheme($store_id, $theme, ($pos !== false) ? substr($path, 0, $pos) : $path, $this->request->post['code']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function reset() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + if (is_file(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function delete() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['theme_id'])) { + $theme_id = $this->request->get['theme_id']; + } else { + $theme_id = 0; + } + + // Check user has permission + if (!$this->user->hasPermission('modify', 'design/theme')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + $this->load->model('design/theme'); + + $this->model_design_theme->deleteTheme($theme_id); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/design/translation.php b/public/admin/controller/design/translation.php new file mode 100644 index 0000000..0740ec1 --- /dev/null +++ b/public/admin/controller/design/translation.php @@ -0,0 +1,509 @@ +<?php +class ControllerDesignTranslation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_translation->addTranslation($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_translation->editTranslation($this->request->get['translation_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $translation_id) { + $this->model_design_translation->deleteTranslation($translation_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'store'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'], true) + ); + + $this->load->model('localisation/language'); + + $data['add'] = $this->url->link('design/translation/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/translation/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['translations'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $translation_total = $this->model_design_translation->getTotalTranslations(); + + $results = $this->model_design_translation->getTranslations($filter_data); + + foreach ($results as $result) { + $data['translations'][] = array( + 'translation_id' => $result['translation_id'], + 'store' => ($result['store_id'] ? $result['store'] : $this->language->get('text_default')), + 'route' => $result['route'], + 'language' => $result['language'], + 'key' => $result['key'], + 'value' => $result['value'], + 'edit' => $this->url->link('design/translation/edit', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $result['translation_id'], true), + ); + } + + $data['user_token'] = $this->session->data['user_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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_store'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url, true); + $data['sort_language'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url, true); + $data['sort_route'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=route' . $url, true); + $data['sort_key'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url, true); + $data['sort_value'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $pagination = new Pagination(); + $pagination->total = $translation_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('design/translation/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($translation_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($translation_total - $this->config->get('config_limit_admin'))) ? $translation_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $translation_total, ceil($translation_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/translation_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['translation_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['translation_id'])) { + $data['action'] = $this->url->link('design/translation/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/translation/edit', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $this->request->get['translation_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['translation_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $translation_info = $this->model_design_translation->getTranslation($this->request->get['translation_id']); + } + + $this->load->model('setting/store'); + + $data['stores'] = $this->model_setting_store->getStores(); + + if (isset($this->request->post['store_id'])) { + $data['store_id'] = $this->request->post['store_id']; + } elseif (!empty($translation_info)) { + $data['store_id'] = $translation_info['store_id']; + } else { + $data['store_id'] = ''; + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (!empty($translation_info)) { + $language = $this->model_localisation_language->getLanguage($translation_info['language_id']); + $code = $language['code']; + } else { + $code = $this->config->get('config_language'); + $language = $this->model_localisation_language->getLanguageByCode($code); + } + + if (isset($this->request->post['language_id'])) { + $data['language_id'] = $this->request->post['language_id']; + } elseif (!empty($translation_info)) { + $data['language_id'] = $translation_info['language_id']; + } else { + $data['language_id'] = $language['language_id']; + } + + if (empty($translation_info)) { + // Get a list of files ready to upload + $data['paths'] = array(); + + $path = glob(DIR_CATALOG . 'language/'.$code.'/*'); + + while (count($path) != 0) { + $next = array_shift($path); + + foreach ((array)glob($next) as $file) { + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + if (substr($file, -4) == '.php') { + $data['paths'][] = substr(substr($file, strlen(DIR_CATALOG . 'language/'.$code.'/')), 0, -4); + } + } + } + } + + if (isset($this->request->post['route'])) { + $data['route'] = $this->request->post['route']; + } elseif (!empty($translation_info)) { + $data['route'] = $translation_info['route']; + } else { + $data['route'] = ''; + } + + if (isset($this->request->post['key'])) { + $data['key'] = $this->request->post['key']; + } elseif (!empty($translation_info)) { + $data['key'] = $translation_info['key']; + } else { + $data['key'] = ''; + } + + if (!empty($translation_info)) { + $directory = DIR_CATALOG . 'language/'; + + if (is_file($directory . $code . '/' . $translation_info['route'] . '.php') && substr(str_replace('\\', '/', realpath($directory . $code . '/' . $translation_info['route'] . '.php')), 0, strlen($directory)) == str_replace('\\', '/', $directory)) { + $_ = array(); + + include($directory . $code . '/' . $translation_info['route'] . '.php'); + + foreach ($_ as $key => $value) { + if ($translation_info['key'] == $key) { + $data['default'] = $value; + } + } + + if (empty($data['default'])) { + $data['default'] = $translation_info['value']; + } + } + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($translation_info)) { + $data['value'] = $translation_info['value']; + } else { + $data['value'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('design/translation_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/translation')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['key']) < 3) || (utf8_strlen($this->request->post['key']) > 64)) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/translation')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function path() { + $this->load->language('design/translation'); + + $json = array(); + + if (isset($this->request->get['language_id'])) { + $language_id = $this->request->get['language_id']; + } else { + $language_id = 0; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($language_id); + + if (!empty($language_info)) { + $path = glob(DIR_CATALOG . 'language/'.$language_info['code'].'/*'); + + while (count($path) != 0) { + $next = array_shift($path); + + foreach ((array)glob($next) as $file) { + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + if (substr($file, -4) == '.php') { + $json[] = substr(substr($file, strlen(DIR_CATALOG . 'language/'.$language_info['code'].'/')), 0, -4); + } + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function translation() { + $this->load->language('design/translation'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + if (isset($this->request->get['language_id'])) { + $language_id = $this->request->get['language_id']; + } else { + $language_id = 0; + } + + if (isset($this->request->get['path'])) { + $route = $this->request->get['path']; + } else { + $route = ''; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($language_id); + + $directory = DIR_CATALOG . 'language/'; + + if ($language_info && is_file($directory . $language_info['code'] . '/' . $route . '.php') && substr(str_replace('\\', '/', realpath($directory . $language_info['code'] . '/' . $route . '.php')), 0, strlen($directory)) == str_replace('\\', '/', $directory)) { + $_ = array(); + + include($directory . $language_info['code'] . '/' . $route . '.php'); + + foreach ($_ as $key => $value) { + $json[] = array( + 'key' => $key, + 'value' => $value + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/error/not_found.php b/public/admin/controller/error/not_found.php new file mode 100644 index 0000000..07be5e2 --- /dev/null +++ b/public/admin/controller/error/not_found.php @@ -0,0 +1,26 @@ +<?php +class ControllerErrorNotFound extends Controller { + public function index() { + $this->load->language('error/not_found'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('error/not_found', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('error/not_found', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/error/permission.php b/public/admin/controller/error/permission.php new file mode 100644 index 0000000..1d2ffd6 --- /dev/null +++ b/public/admin/controller/error/permission.php @@ -0,0 +1,26 @@ +<?php +class ControllerErrorPermission extends Controller { + public function index() { + $this->load->language('error/permission'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link($this->request->get['route'], 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('error/permission', $data)); + } +} diff --git a/public/admin/controller/event/language.php b/public/admin/controller/event/language.php new file mode 100644 index 0000000..5049b7d --- /dev/null +++ b/public/admin/controller/event/language.php @@ -0,0 +1,26 @@ +<?php +class ControllerEventLanguage extends Controller { + public function index(&$route, &$args) { + foreach ($this->language->all() as $key => $value) { + if (!isset($args[$key])) { + $args[$key] = $value; + } + } + } + + // 1. Before controller load store all current loaded language data + public function before(&$route, &$output) { + $this->language->set('backup', $this->language->all()); + } + + // 2. After contoller load restore old language data + public function after(&$route, &$args, &$output) { + $data = $this->language->get('backup'); + + if (is_array($data)) { + foreach ($data as $key => $value) { + $this->language->set($key, $value); + } + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/event/statistics.php b/public/admin/controller/event/statistics.php new file mode 100644 index 0000000..46e55e2 --- /dev/null +++ b/public/admin/controller/event/statistics.php @@ -0,0 +1,16 @@ +<?php +class ControllerEventStatistics extends Controller { + // model/catalog/review/removeReview/after + public function removeReview(&$route, &$args, &$output) { + $this->load->model('setting/statistics'); + + $this->model_report_statistics->addValue('review', 1); + } + + // model/sale/return/removeReturn/after + public function removeReturn(&$route, &$args, &$output) { + $this->load->model('setting/statistics'); + + $this->model_report_statistics->addValue('return', 1); + } +}
\ No newline at end of file diff --git a/public/admin/controller/event/theme.php b/public/admin/controller/event/theme.php new file mode 100644 index 0000000..3148f13 --- /dev/null +++ b/public/admin/controller/event/theme.php @@ -0,0 +1,15 @@ +<?php +class ControllerEventTheme extends Controller { + public function index(&$route, &$args) { + // This is only here for compatibility with old templates + if (substr($route, -3) == 'tpl') { + $view = substr($route, 0, -3); + } + + if (is_file(DIR_TEMPLATE . $route . '.twig')) { + $this->config->set('template_engine', 'twig'); + } elseif (is_file(DIR_TEMPLATE . $route . '.tpl')) { + $this->config->set('template_engine', 'template'); + } + } +} diff --git a/public/admin/controller/extension/advertise/google.php b/public/admin/controller/extension/advertise/google.php new file mode 100644 index 0000000..fa24904 --- /dev/null +++ b/public/admin/controller/extension/advertise/google.php @@ -0,0 +1,2089 @@ +<?php + +use \googleshopping\exception\Connection as ConnectionException; +use \googleshopping\Googleshopping; +use \googleshopping\traits\LibraryLoader; +use \googleshopping\traits\StoreLoader; + +class ControllerExtensionAdvertiseGoogle extends Controller { + use StoreLoader; + use LibraryLoader; + + private $error = array(); + private $store_id = 0; + + public function __construct($registry) { + parent::__construct($registry); + + $this->store_id = isset($this->request->get['store_id']) ? (int)$this->request->get['store_id'] : 0; + + $this->loadStore($this->store_id); + + $this->loadLibrary($this->store_id); + } + + public function index() { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $this->load->config('googleshopping/googleshopping'); + + // Fix clashes with third-party extension table names + $this->model_extension_advertise_google->renameTables(); + + // Even though this should be ran during install, there are known cases of webstores which do not trigger the install method. This is why we run createTables here explicitly. + $this->model_extension_advertise_google->createTables(); + + // Fix a missing AUTO_INCREMENT + $this->model_extension_advertise_google->fixColumns(); + + // Redirect to the preliminary check-list + if (!$this->setting->get('advertise_google_checklist_confirmed')) { + $this->response->redirect($this->url->link('extension/advertise/google/checklist', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + try { + // If we have not connected, navigate to connect screen + if (!$this->setting->has('advertise_google_access_token')) { + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->setting->has('advertise_google_gmc_account_selected')) { + // In case the merchant has made no decision about which GMC account to use, redirect to the form for connection + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->googleshopping->isStoreUrlClaimed()) { + if (empty($this->session->data['error'])) { + $this->session->data['error'] = $this->language->get('error_store_url_claim'); + } + + // In case the merchant has made no decision about which GMC account to use, redirect to the form for connection + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (count($this->googleshopping->getTargets($this->store_id)) == 0) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->setting->has('advertise_google_gmc_shipping_taxes_configured')) { + // In case the merchant has not set up shipping and taxes, redirect them to the form for shipping and taxes + $this->response->redirect($this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (count($this->model_extension_advertise_google->getMapping($this->store_id)) == 0) { + // In case the merchant has not set up mapping, redirect them to the form for mapping + $this->response->redirect($this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + // Pull the campaign reports + $this->googleshopping->getCampaignReports(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateSettings()) { + $this->applyNewSettings($this->request->post); + + try { + // Profilactic target push, as sometimes targets are not initialized properly + $this->googleshopping->pushTargets(); + $this->googleshopping->pushCampaignStatus(); + + $this->session->data['success'] = $this->language->get('success_index'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data = array(); + + $data['text_connected'] = sprintf($this->language->get('text_connected'), $this->setting->get('advertise_google_gmc_account_id')); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $advertised_count = $this->model_extension_advertise_google->getAdvertisedCount($this->store_id); + $last_cron_executed = (int)$this->setting->get('advertise_google_cron_last_executed'); + + $data['warning'] = ''; + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = $this->language->get('warning_disabled'); + } else if (!$this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = sprintf($this->language->get('warning_no_active_campaigns'), $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true)); + } else if ($advertised_count == 0) { + $data['warning'] = sprintf($this->language->get("warning_no_advertised_products"), $this->language->get("text_video_tutorial_url_advertise")); + } else if ($last_cron_executed + 24 * 60 * 60 <= time()) { + $data['warning'] = sprintf($this->language->get("warning_last_cron_executed"), $this->language->get("text_tutorial_cron")); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $reporting_intervals = $this->config->get('advertise_google_reporting_intervals'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['shipping_taxes'] = $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['campaign'] = $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['mapping'] = $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['disconnect'] = $this->url->link('extension/advertise/google/disconnect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['list_ads'] = html_entity_decode($this->url->link('extension/advertise/google/list_ads', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['advertise'] = html_entity_decode($this->url->link('extension/advertise/google/advertise', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_popup'] = html_entity_decode($this->url->link('extension/advertise/google/popup_product', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_category_autocomplete'] = html_entity_decode($this->url->link('extension/advertise/google/category_autocomplete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_debug_log_download'] = html_entity_decode($this->url->link('extension/advertise/google/debug_log_download', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + + $data['advertise_google_status'] = $this->getSettingValue('advertise_google_status', 0); + $data['advertise_google_debug_log'] = $this->getSettingValue('advertise_google_debug_log', 0); + $data['advertise_google_cron_email_status'] = $this->getSettingValue('advertise_google_cron_email_status'); + $data['advertise_google_cron_email'] = $this->getSettingValue('advertise_google_cron_email', $this->config->get('config_email')); + $data['advertise_google_cron_token'] = $this->getSettingValue('advertise_google_cron_token'); + $data['advertise_google_cron_acknowledge'] = $this->getSettingValue('advertise_google_cron_acknowledge', null, true); + + if (isset($this->request->post['advertise_google_reporting_interval'])) { + $data['advertise_google_reporting_interval'] = $this->request->post['advertise_google_reporting_interval']; + } else if ($this->setting->has('advertise_google_reporting_interval') && in_array($this->setting->get('advertise_google_reporting_interval'), $reporting_intervals)) { + $data['advertise_google_reporting_interval'] = $this->setting->get('advertise_google_reporting_interval'); + } else { + $data['advertise_google_reporting_interval'] = $this->config->get('advertise_google_reporting_intervals_default'); + } + + $server = $this->googleshopping->getStoreUrl(); + + $data['advertise_google_cron_command'] = 'export CUSTOM_SERVER_NAME=' . parse_url($server, PHP_URL_HOST) . '; export CUSTOM_SERVER_PORT=443; export ADVERTISE_GOOGLE_CRON=1; export ADVERTISE_GOOGLE_STORE_ID=' . $this->store_id . '; ' . PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' -d memory_limit=256M ' . DIR_SYSTEM . 'library/googleshopping/cron.php > /dev/null 2> /dev/null'; + + if (!$this->setting->get('advertise_google_cron_token')) { + $data['advertise_google_cron_token'] = md5(mt_rand()); + } + + $host_and_uri = parse_url($server, PHP_URL_HOST) . parse_url($server, PHP_URL_PATH); + + $data['advertise_google_cron_url'] = 'https://' . rtrim($host_and_uri, '/') . '/index.php?route=extension/advertise/google/cron&cron_token={CRON_TOKEN}'; + + $data['reporting_intervals'] = array(); + + foreach ($reporting_intervals as $interval) { + $data['reporting_intervals'][$interval] = $this->language->get('text_reporting_interval_' . $interval); + } + + $campaign_reports = $this->setting->get('advertise_google_report_campaigns'); + + $data['campaigns'] = $this->googleshopping->getTargets($this->store_id); + + $data['text_report_date_range'] = sprintf($this->language->get('text_report_date_range'), $campaign_reports['date_range']); + $data['text_ads_intro'] = sprintf($this->language->get('text_ads_intro'), $data['shipping_taxes']); + $data['advertise_google_report_campaigns'] = $campaign_reports['reports']; + $data['text_panel_heading'] = sprintf($this->language->get('text_panel_heading'), $this->googleshopping->getStoreName()); + + $data['text_selection_all'] = str_replace("'", "\\'", $this->language->get('text_selection_all')); + $data['text_selection_page'] = str_replace("'", "\\'", $this->language->get('text_selection_page')); + + $data['tab_settings'] = $this->load->view('extension/advertise/google_settings', $data); + $data['tab_ads'] = $this->load->view('extension/advertise/google_ads', $data); + $data['tab_reports'] = $this->load->view('extension/advertise/google_reports', $data); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/advertise/google', $data)); + } + + public function debug_log_download() { + $filename = sprintf(Googleshopping::DEBUG_LOG_FILENAME, $this->store_id); + + header('Pragma: no-cache'); + header('Expires: 0'); + header('Content-Description: File Transfer'); + header('Content-Type: plain/text'); + header('Content-Disposition: attachment; filename="' . $filename . '"'); + header('Content-Transfer-Encoding: binary'); + + $file = DIR_LOGS . $filename; + + if (file_exists($file)) { + readfile($file); + } + + exit; + } + + public function advertise() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null, + 'warning' => null + ); + + if ($this->validatePermission()) { + $this->load->model('extension/advertise/google'); + + $select = array(); + $filter_data = array(); + + if (!empty($this->request->post['all_pages'])) { + $filter_data = $this->getFilter($this->request->post['filter']); + } else if (isset($this->request->post['select']) && is_array($this->request->post['select'])) { + $select = $this->request->post['select']; + } + + if (!empty($select) || !empty($filter_data)) { + $target_ids = !empty($this->request->post['target_ids']) ? $this->request->post['target_ids'] : array(); + + if (!empty($select)) { + $this->model_extension_advertise_google->setAdvertisingBySelect($select, $target_ids, $this->store_id); + } else if (!empty($filter_data)) { + $this->model_extension_advertise_google->setAdvertisingByFilter($filter_data, $target_ids, $this->store_id); + } + + if (!empty($target_ids)) { + $json['success'] = $this->language->get('success_advertise_listed'); + } else { + $json['success'] = $this->language->get('success_advertise_unlisted'); + } + } + } else { + $json['error'] = $this->error['warning']; + } + + // Refresh warnings + $advertised_count = $this->model_extension_advertise_google->getAdvertisedCount($this->store_id); + $last_cron_executed = (int)$this->setting->get('advertise_google_cron_last_executed'); + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $json['warning'] = $this->language->get('warning_disabled'); + } else if (!$this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $json['warning'] = sprintf($this->language->get('warning_no_active_campaigns'), $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true)); + } else if ($advertised_count == 0) { + $json['warning'] = sprintf($this->language->get("warning_no_advertised_products"), $this->language->get("text_video_tutorial_url_advertise")); + } else if ($last_cron_executed + 24 * 60 * 60 <= time()) { + $json['warning'] = sprintf($this->language->get("warning_last_cron_executed"), $this->language->get("text_tutorial_cron")); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function list_ads() { + $json = array(); + + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->insertNewProducts(array(), $this->store_id); + + $this->load->language('extension/advertise/google'); + + $page = (int)$this->request->post['page']; + + $filter_data = array( + 'sort' => $this->request->post['sort'], + 'order' => $this->request->post['order'], + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $filter_data = array_merge($filter_data, $this->getFilter($this->request->post['filter'])); + + $products = $this->googleshopping->getProducts($filter_data, $this->store_id); + + $json['products'] = array_map(array($this, 'product'), $products); + + $product_total = $this->googleshopping->getTotalProducts($filter_data, $this->store_id); + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $this->request->post['page']; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = '{page}'; + + $pages = ceil($product_total / $this->config->get('config_limit_admin')); + + $json['showing'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, $pages); + + $json['pagination'] = $pagination->render(); + $json['total'] = (int)$product_total; + $json['pages'] = (int)$pages; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function merchant() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_merchant')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validatePermission()) { + try { + $redirect_uri = html_entity_decode($this->url->link('extension/advertise/google/callback_merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $state = md5(microtime(true) . $redirect_uri . microtime(true)); + + $auth_url_data = array( + 'account_type' => $this->request->post['advertise_google_gmc_account_type'], + 'redirect_uri' => $redirect_uri . '&state=' . $state + ); + + $this->session->data['advertise_google'] = $auth_url_data; + $this->session->data['advertise_google']['state'] = $state; + + $this->response->redirect($this->googleshopping->getMerchantAuthUrl($auth_url_data)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['advertise_google_gmc_account_type'])) { + $data['advertise_google_gmc_account_type'] = $this->request->post['advertise_google_gmc_account_type']; + } else { + $data['advertise_google_gmc_account_type'] = 'api'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 2; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_merchant', $data)); + } + + public function shipping_taxes() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_shipping_taxes')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + $this->load->config('googleshopping/googleshopping'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateShippingAndTaxes()) { + try { + $this->applyNewSettings($this->request->post); + + $this->googleshopping->pushShippingAndTaxes(); + + $this->applyNewSettings(array( + 'advertise_google_gmc_shipping_taxes_configured' => '1' + )); + + $this->session->data['success'] = $this->language->get('success_shipping_taxes'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $available_carriers = array(); + + try { + $available_carriers = $this->googleshopping->getAvailableCarriers(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + if (isset($this->error['min_transit_time'])) { + $data['error_min_transit_time'] = $this->error['min_transit_time']; + } else { + $data['error_min_transit_time'] = ''; + } + + if (isset($this->error['max_transit_time'])) { + $data['error_max_transit_time'] = $this->error['max_transit_time']; + } else { + $data['error_max_transit_time'] = ''; + } + + if (isset($this->error['flat_rate'])) { + $data['error_flat_rate'] = $this->error['flat_rate']; + } else { + $data['error_flat_rate'] = ''; + } + + if (isset($this->error['carrier_postcode'])) { + $data['error_carrier_postcode'] = $this->error['carrier_postcode']; + } else { + $data['error_carrier_postcode'] = ''; + } + + if (isset($this->error['carrier_price_percentage'])) { + $data['error_carrier_price_percentage'] = $this->error['carrier_price_percentage']; + } else { + $data['error_carrier_price_percentage'] = ''; + } + + if (isset($this->error['carrier'])) { + $data['error_carrier'] = $this->error['carrier']; + } else { + $data['error_carrier'] = ''; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_shipping_taxes'), + 'href' => $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['advertise_google_shipping_taxes'])) { + $data['advertise_google_shipping_taxes'] = $this->request->post['advertise_google_shipping_taxes']; + } else if ($this->setting->has('advertise_google_shipping_taxes')) { + $data['advertise_google_shipping_taxes'] = $this->setting->get('advertise_google_shipping_taxes'); + } else { + $data['advertise_google_shipping_taxes'] = array( + 'shipping_type' => 'flat', + 'flat_rate' => $this->config->get('shipping_flat_cost'), + 'min_transit_time' => 1, + 'max_transit_time' => 14, + 'carrier_price_percentage' => 5, + 'tax_type' => $this->config->get('config_country_id') == 223 ? 'usa' : 'not_usa' + ); + } + + $data['available_carriers'] = $available_carriers; + + $data['states'] = $this->config->get('advertise_google_tax_usa_states'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 4; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_shipping_taxes', $data)); + } + + public function mapping() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_mapping')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateMapping()) { + try { + foreach ($this->request->post['advertise_google_mapping'] as $google_product_category => $category_id) { + $this->model_extension_advertise_google->setCategoryMapping($google_product_category, $this->store_id, $category_id); + } + + if (!empty($this->request->post['advertise_google_modify_existing'])) { + $this->model_extension_advertise_google->updateGoogleProductCategoryMapping($this->store_id); + } + + $this->session->data['success'] = $this->language->get('success_mapping'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_shipping_taxes'), + 'href' => $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + $this->load->config('googleshopping/googleshopping'); + + $data['mapping'] = array(); + + foreach ($this->config->get('advertise_google_google_product_categories') as $google_product_category_id => $google_product_category_name) { + if ($google_product_category_id == 0) continue; + + $category_id = ''; + $name = ''; + + if (null !== $category = $this->model_extension_advertise_google->getMappedCategory($google_product_category_id, $this->store_id)) { + $category_id = $category['category_id']; + $name = $category['name']; + } + + $map = array( + 'google_product_category' => array( + 'id' => $google_product_category_id, + 'name' => $google_product_category_name + ), + 'oc_category' => array( + 'category_id' => $category_id, + 'name' => $name + ) + ); + + $data['mapping'][] = $map; + } + + $data['mapping_json'] = json_encode($data['mapping']); + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['url_mapping_verify'] = html_entity_decode($this->url->link('extension/advertise/google/mapping_verify', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_category_autocomplete'] = html_entity_decode($this->url->link('extension/advertise/google/category_autocomplete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 5; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_mapping', $data)); + } + + public function mapping_verify() { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $data = array(); + + $json = array( + 'submit_directly' => !$this->model_extension_advertise_google->isAnyProductCategoryModified($this->store_id), + 'modal_confirmation' => $this->load->view('extension/advertise/google_mapping_verify', $data) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function campaign_test() { + $json = array( + 'status' => false, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + try { + $json['status'] = $this->googleshopping->testCampaigns(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['status'] = false; + $json['error'] = $e->getMessage(); + } + + $this->applyNewSettings(array( + 'advertise_google_can_edit_campaigns' => (int)$json['status'] + )); + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function campaign() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_campaign')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateCampaign()) { + $this->applyNewSettings($this->request->post); + + // If there is no redirect from the push of targets, go back to the extension dashboard + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['warning'] = ''; + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = $this->language->get('warning_paused_targets'); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_campaign'), + 'href' => $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + if (isset($this->request->post['advertise_google_auto_advertise'])) { + $data['advertise_google_auto_advertise'] = $this->request->post['advertise_google_auto_advertise']; + } else if ($this->setting->has('advertise_google_auto_advertise')) { + $data['advertise_google_auto_advertise'] = $this->setting->get('advertise_google_auto_advertise'); + } else { + $data['advertise_google_auto_advertise'] = '0'; + } + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['target_add'] = html_entity_decode($this->url->link('extension/advertise/google/target_add', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['target_edit'] = html_entity_decode($this->url->link('extension/advertise/google/target_edit', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&advertise_google_target_id={target_id}', true), ENT_QUOTES, 'UTF-8'); + $data['target_delete'] = html_entity_decode($this->url->link('extension/advertise/google/target_delete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&advertise_google_target_id={target_id}', true), ENT_QUOTES, 'UTF-8'); + $data['target_list'] = html_entity_decode($this->url->link('extension/advertise/google/target_list', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_campaign_test'] = html_entity_decode($this->url->link('extension/advertise/google/campaign_test', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['can_edit_campaigns'] = (bool)$this->setting->get('advertise_google_can_edit_campaigns'); + $data['text_roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), time() + Googleshopping::ROAS_WAIT_INTERVAL)); + + $data['json_allowed_targets'] = json_encode($this->model_extension_advertise_google->getAllowedTargets()); + + $targets = $this->googleshopping->getTargets($this->store_id); + + foreach ($targets as &$target) { + if (!$target['roas_status']) { + $target['roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), $target['roas_available_on'])); + } else { + $target['roas_warning'] = null; + } + } + + $data['targets'] = $targets; + $data['json_targets'] = json_encode($targets); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 3; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_campaign', $data)); + } + + public function target_add() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateTarget()) { + $this->load->model('extension/advertise/google'); + + $target = array( + 'store_id' => $this->store_id, + 'campaign_name' => str_replace(',', ',', trim($this->request->post['campaign_name'])), + 'country' => $this->request->post['country'], + 'status' => $this->request->post['status'] == 'active' ? 'active' : 'paused', + 'budget' => (float)preg_replace('~[^0-9\.]~i', '', $this->request->post['budget']), + 'roas' => isset($this->request->post['roas']) ? (int)$this->request->post['roas'] : 0, + 'feeds' => array_values($this->request->post['feed']) + ); + + $this->model_extension_advertise_google->addTarget($target, $this->store_id); + + try { + $this->googleshopping->pushTargets(); + + $json['success'] = $this->language->get('success_target_add'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } else { + $json['error'] = $this->error['warning']; + + if (isset($this->error['campaign_name'])) { + $json['error_campaign_name'] = $this->error['campaign_name']; + } + + if (isset($this->error['country'])) { + $json['error_country'] = $this->error['country']; + } + + if (isset($this->error['budget'])) { + $json['error_budget'] = $this->error['budget']; + } + + if (isset($this->error['feed'])) { + $json['error_feed'] = $this->error['feed']; + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_edit() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateTarget()) { + $this->load->model('extension/advertise/google'); + + $target = array( + 'campaign_name' => str_replace(',', ',', trim($this->request->post['campaign_name'])), + 'country' => $this->request->post['country'], + 'status' => $this->request->post['status'] == 'active' ? 'active' : 'paused', + 'budget' => (float)preg_replace('~[^0-9\.]~i', '', $this->request->post['budget']), + 'roas' => isset($this->request->post['roas']) ? (int)$this->request->post['roas'] : 0, + 'feeds' => array_values($this->request->post['feed']) + ); + + $this->googleshopping->editTarget((int)$this->request->get['advertise_google_target_id'], $target); + + try { + $this->googleshopping->pushTargets(); + + $json['success'] = $this->language->get('success_target_edit'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } else { + $json['error'] = $this->error['warning']; + + if (isset($this->error['campaign_name'])) { + $json['error_campaign_name'] = $this->error['campaign_name']; + } + + if (isset($this->error['country'])) { + $json['error_country'] = $this->error['country']; + } + + if (isset($this->error['budget'])) { + $json['error_budget'] = $this->error['budget']; + } + + if (isset($this->error['feed'])) { + $json['error_feed'] = $this->error['feed']; + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_delete() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + $this->load->model('extension/advertise/google'); + + $advertise_google_target_id = (int)$this->request->get['advertise_google_target_id']; + + $target_info = $this->googleshopping->getTarget($advertise_google_target_id); + + if (!empty($target_info)) { + try { + $this->googleshopping->deleteCampaign($target_info['campaign_name']); + + $this->googleshopping->deleteTarget($advertise_google_target_id); + + $json['success'] = $this->language->get('success_target_delete'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_list() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'targets' => null, + 'error' => null + ); + + $this->load->model('extension/advertise/google'); + + $targets = $this->googleshopping->getTargets($this->store_id); + + foreach ($targets as &$target) { + if (!$target['roas_status']) { + $target['roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), $target['roas_available_on'])); + } else { + $target['roas_warning'] = null; + } + } + + $json['targets'] = $targets; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function callback_merchant() { + $state_verified = + !empty($this->session->data['advertise_google']['state']) && + !empty($this->request->get['state']) && + $this->request->get['state'] == $this->session->data['advertise_google']['state']; + + $error = isset($this->request->get['error']) ? $this->request->get['error'] : null; + $merchant_id = isset($this->request->get['merchant_id']) ? $this->request->get['merchant_id'] : null; + + if ($state_verified && is_null($error)) { + $this->load->language('extension/advertise/google'); + + try { + $this->googleshopping->verifySite(); + + $this->load->model('user/user'); + $user_info = $this->model_user_user->getUser($this->user->getId()); + + $this->applyNewSettings(array( + 'advertise_google_gmc_account_selected' => true, + 'advertise_google_gmc_account_id' => $merchant_id, + 'advertise_google_gmc_account_accepted_by' => array( + 'user_id' => $user_info['user_id'], + 'user_group_id' => $user_info['user_group_id'], + 'user_group' => $user_info['user_group'], + 'username' => $user_info['username'], + 'firstname' => $user_info['firstname'], + 'lastname' => $user_info['lastname'], + 'email' => $user_info['email'], + 'ip' => $user_info['ip'] + ), + 'advertise_google_gmc_account_accepted_at' => time(), + 'advertise_google_conversion_tracker' => $this->googleshopping->getConversionTracker(), + 'advertise_google_can_edit_campaigns' => '0' + )); + + if ($this->session->data['advertise_google']['account_type'] == 'api') { + $this->session->data['success'] = sprintf($this->language->get('success_merchant_access'), $merchant_id); + } else { + $this->session->data['success'] = $this->language->get('success_merchant'); + } + + if (count($this->googleshopping->getTargets($this->store_id)) > 0) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + unset($this->session->data['advertise_google']); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else if (!is_null($error)) { + $this->session->data['error'] = $error; + + $setting = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + unset($setting['advertise_google_status']); + unset($setting['advertise_google_work']); + unset($setting['advertise_google_gmc_account_selected']); + unset($setting['advertise_google_gmc_shipping_taxes_configured']); + unset($setting['advertise_google_can_edit_campaigns']); + + $this->model_setting_setting->editSetting('advertise_google', $setting, $this->store_id); + } + + unset($this->session->data['advertise_google']); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function callback_connect() { + $state_verified = + !empty($this->session->data['advertise_google']['state']) && + !empty($this->request->get['state']) && + $this->request->get['state'] == $this->session->data['advertise_google']['state']; + + if ($state_verified) { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + try { + $access = $this->googleshopping->access($this->session->data['advertise_google'], urldecode($this->request->get['code'])); + + $this->applyNewSettings(array( + 'advertise_google_app_id' => $this->session->data['advertise_google']['app_id'], + 'advertise_google_app_secret' => $this->session->data['advertise_google']['app_secret'], + 'advertise_google_status' => $this->session->data['advertise_google']['status'], + 'advertise_google_cron_token' => $this->session->data['advertise_google']['cron_token'], + 'advertise_google_cron_acknowledge' => $this->session->data['advertise_google']['cron_acknowledge'], + 'advertise_google_cron_email' => $this->session->data['advertise_google']['cron_email'], + 'advertise_google_cron_email_status' => $this->session->data['advertise_google']['cron_email_status'], + 'advertise_google_access_token' => $access['access_token'], + 'advertise_google_refresh_token' => $access['refresh_token'] + )); + + $this->session->data['success'] = $this->language->get('success_connect'); + + if (count($this->googleshopping->getTargets($this->store_id)) > 0 && $this->setting->get('advertise_google_gmc_account_selected')) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else if (isset($this->request->get['error'])) { + $this->session->data['error'] = $this->request->get['error']; + } + + unset($this->session->data['advertise_google']); + + if ($this->setting->get('advertise_google_gmc_account_selected')) { + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else { + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } + + public function connect() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateSettings() && $this->validateConnect()) { + unset($this->session->data['advertise_google']); + + $this->session->data['advertise_google']['app_id'] = $this->request->post['advertise_google_app_id']; + $this->session->data['advertise_google']['app_secret'] = $this->request->post['advertise_google_app_secret']; + $this->session->data['advertise_google']['status'] = $this->request->post['advertise_google_status']; + $this->session->data['advertise_google']['cron_email_status'] = $this->request->post['advertise_google_cron_email_status']; + $this->session->data['advertise_google']['cron_email'] = $this->request->post['advertise_google_cron_email']; + $this->session->data['advertise_google']['cron_token'] = $this->request->post['advertise_google_cron_token']; + $this->session->data['advertise_google']['cron_acknowledge'] = isset($this->request->post['advertise_google_cron_acknowledge']); + $this->session->data['advertise_google']['redirect_uri'] = html_entity_decode($this->url->link('extension/advertise/google/callback_connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $this->session->data['advertise_google']['state'] = md5(microtime(true) . json_encode($this->session->data['advertise_google']) . microtime(true)); + + $url = $this->googleshopping->authorize($this->session->data['advertise_google']); + + $this->response->redirect($url); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + if (empty($this->session->data['success']) && $this->getSettingValue('advertise_google_app_id', false) && $this->getSettingValue('advertise_google_app_secret', false)) { + $data['error'] = $this->session->data['error']; + } + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['app_secret'])) { + $data['error_app_secret'] = $this->error['app_secret']; + } else { + $data['error_app_secret'] = ''; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['advertise_google_status'] = $this->getSettingValue('advertise_google_status', 1); + $data['advertise_google_app_id'] = $this->getSettingValue('advertise_google_app_id', ''); + $data['advertise_google_app_secret'] = $this->getSettingValue('advertise_google_app_secret', ''); + $data['advertise_google_cron_email_status'] = $this->getSettingValue('advertise_google_cron_email_status'); + $data['advertise_google_cron_email'] = $this->getSettingValue('advertise_google_cron_email', $this->config->get('config_email')); + $data['advertise_google_cron_token'] = $this->getSettingValue('advertise_google_cron_token'); + $data['advertise_google_cron_acknowledge'] = $this->getSettingValue('advertise_google_cron_acknowledge', null, true); + + $server = $this->googleshopping->getStoreUrl(); + + $data['advertise_google_cron_command'] = 'export CUSTOM_SERVER_NAME=' . parse_url($server, PHP_URL_HOST) . '; export CUSTOM_SERVER_PORT=443; export ADVERTISE_GOOGLE_CRON=1; export ADVERTISE_GOOGLE_STORE_ID=' . $this->store_id . '; ' . PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' -d memory_limit=256M ' . DIR_SYSTEM . 'library/googleshopping/cron.php > /dev/null 2> /dev/null'; + + if (!$this->setting->get('advertise_google_cron_token')) { + $data['advertise_google_cron_token'] = md5(mt_rand()); + } + + $host_and_uri = parse_url($server, PHP_URL_HOST) . dirname(parse_url($server, PHP_URL_PATH)); + + $data['advertise_google_cron_url'] = 'https://' . rtrim($host_and_uri, '/') . '/index.php?route=extension/advertise/google/cron&cron_token={CRON_TOKEN}'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['text_connect_intro'] = sprintf($this->language->get('text_connect_intro'), Googleshopping::API_URL); + + $data['current_step'] = 1; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_connect', $data)); + } + + public function disconnect() { + $this->load->language('extension/advertise/google'); + + if ($this->validatePermission()) { + try { + $this->load->model('setting/setting'); + + $this->googleshopping->disconnect(); + + foreach ($this->googleshopping->getTargets($this->store_id) as $target) { + $this->googleshopping->deleteTarget($target['target_id']); + } + + $setting = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + unset($setting['advertise_google_status']); + unset($setting['advertise_google_work']); + unset($setting['advertise_google_access_token']); + unset($setting['advertise_google_refresh_token']); + unset($setting['advertise_google_gmc_account_selected']); + unset($setting['advertise_google_gmc_shipping_taxes_configured']); + unset($setting['advertise_google_can_edit_campaigns']); + + $this->model_setting_setting->editSetting('advertise_google', $setting, $this->store_id); + + $this->session->data['success'] = $this->language->get('success_disconnect'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else { + $this->session->data['error'] = $this->error['warning']; + } + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function checklist() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validatePermission()) { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('advertise_google', $this->request->post, $this->store_id); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['text_panel_heading'] = sprintf($this->language->get('text_panel_heading'), $this->googleshopping->getStoreName()); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/checklist', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/advertise/google_checklist', $data)); + } + + public function popup_product() { + $json = array( + 'body' => '', + 'title' => '', + 'success' => false, + 'required_fields' => [], + 'success_message' => '' + ); + + $this->language->load('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $operand_info = NULL; + $form_data = NULL; + $filter_data = NULL; + $product_ids = array(); + + if ($this->request->post['operand']['type'] == 'single') { + $product_advertise_google_id = $this->request->post['operand']['data']; + + $product_info = $this->model_extension_advertise_google->getProductByProductAdvertiseGoogleId($product_advertise_google_id); + + if ($product_info !== NULL) { + $json['product_id'] = $product_info['product_id']; + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_single'), $product_info['name'], $product_info['model']) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByProductIds(array($product_info['product_id']), $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = array_merge($this->request->post['form'], array( + 'product_id' => $product_info['product_id'] + )); + } + + $options = $this->model_extension_advertise_google->getProductOptionsByProductIds(array($product_info['product_id'])); + + $default_form_data = $this->model_extension_advertise_google->getProductAdvertiseGoogle($product_advertise_google_id); + } + } else if ($this->request->post['operand']['type'] == 'multiple') { + if (!empty($this->request->post['operand']['data']['all_pages'])) { + $filter_data = $this->getFilter($this->request->post['operand']['data']['filter']); + + $total_products = $this->googleshopping->getTotalProducts($filter_data, $this->store_id); + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_multiple'), $total_products) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByFilter($filter_data, $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } + + $options = $this->model_extension_advertise_google->getProductOptionsByFilter($filter_data); + } else { + $product_ids = $this->request->post['operand']['data']['select']; + + $total_products = count($product_ids); + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_multiple'), $total_products) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByProductIds($product_ids, $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } + + $options = $this->model_extension_advertise_google->getProductOptionsByProductIds($product_ids); + } + + $default_form_data = array( + 'google_product_category' => '', + 'condition' => '', + 'adult' => '', + 'multipack' => '', + 'is_bundle' => '', + 'age_group' => '', + 'color' => '', + 'gender' => '', + 'size_type' => '', + 'size_system' => '', + 'size' => '' + ); + } + + if ($operand_info !== NULL) { + $json['title'] = $operand_info['title']; + $json['success_message'] = $this->language->get('success_product'); + + $this->load->config('googleshopping/googleshopping'); + + $json['required_fields'] = $required_fields; + + if ($this->request->post['action'] == 'submit' && $this->validateProduct($required_fields)) { + $form_data['store_id'] = (int)$this->store_id; + + if ($this->request->post['operand']['type'] == 'single') { + $this->model_extension_advertise_google->updateSingleProductFields($form_data); + } else if ($this->request->post['operand']['type'] == 'multiple') { + if (!empty($this->request->post['operand']['data']['all_pages'])) { + $this->model_extension_advertise_google->updateMultipleProductFields($filter_data, $form_data); + } else { + foreach ($product_ids as $product_id) { + $form_data['product_id'] = (int)$product_id; + $this->model_extension_advertise_google->updateSingleProductFields($form_data); + } + } + } + + $json['success'] = true; + } + + $data['error'] = ''; + + if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + if (isset($this->error['color'])) { + $data['error_color'] = $this->error['color']; + } else { + $data['error_color'] = ''; + } + + if (isset($this->error['size_system'])) { + $data['error_size_system'] = $this->error['size_system']; + } else { + $data['error_size_system'] = ''; + } + + if (isset($this->error['size_type'])) { + $data['error_size_type'] = $this->error['size_type']; + } else { + $data['error_size_type'] = ''; + } + + if (isset($this->error['size'])) { + $data['error_size'] = $this->error['size']; + } else { + $data['error_size'] = ''; + } + + if (isset($this->error['product_category'])) { + $data['error_product_category'] = $this->error['product_category']; + } else { + $data['error_product_category'] = ''; + } + + if (isset($this->error['condition'])) { + $data['error_condition'] = $this->error['condition']; + } else { + $data['error_condition'] = ''; + } + + if (isset($this->error['age_group'])) { + $data['error_age_group'] = $this->error['age_group']; + } else { + $data['error_age_group'] = ''; + } + + if (isset($this->error['gender'])) { + $data['error_gender'] = $this->error['gender']; + } else { + $data['error_gender'] = ''; + } + + if (isset($this->error['adult'])) { + $data['error_adult'] = $this->error['adult']; + } else { + $data['error_adult'] = ''; + } + + if (isset($this->error['multipack'])) { + $data['error_multipack'] = $this->error['multipack']; + } else { + $data['error_multipack'] = ''; + } + + if (isset($this->error['is_bundle'])) { + $data['error_is_bundle'] = $this->error['is_bundle']; + } else { + $data['error_is_bundle'] = ''; + } + + $data['google_product_categories'] = $this->config->get('advertise_google_google_product_categories'); + $data['conditions'] = array( + 'new' => $this->language->get('text_condition_new'), + 'refurbished' => $this->language->get('text_condition_refurbished'), + 'used' => $this->language->get('text_condition_used') + ); + $data['age_groups'] = array( + '' => $this->language->get('text_does_not_apply'), + 'newborn' => $this->language->get('text_age_group_newborn'), + 'infant' => $this->language->get('text_age_group_infant'), + 'toddler' => $this->language->get('text_age_group_toddler'), + 'kids' => $this->language->get('text_age_group_kids'), + 'adult' => $this->language->get('text_age_group_adult') + ); + $data['genders'] = array( + 'unisex' => $this->language->get('text_gender_unisex'), + 'female' => $this->language->get('text_gender_female'), + 'male' => $this->language->get('text_gender_male') + ); + $data['size_systems'] = array( + '' => $this->language->get('text_does_not_apply') + ); + foreach ($this->config->get('advertise_google_size_systems') as $system) { + $data['size_systems'][$system] = $system; + } + + $data['size_types'] = array( + '' => $this->language->get('text_does_not_apply'), + 'regular' => $this->language->get('text_size_type_regular'), + 'petite' => $this->language->get('text_size_type_petite'), + 'plus' => $this->language->get('text_size_type_plus'), + 'big and tall' => $this->language->get('text_size_type_big_and_tall'), + 'maternity' => $this->language->get('text_size_type_maternity') + ); + + $data['options'] = array( + '' => $this->language->get('text_does_not_apply') + ); + + foreach ($options as $option) { + $data['options'][$option['option_id']] = $option['name']; + } + + $data['required_fields'] = json_encode($required_fields); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } else { + $form_data = $default_form_data; + } + + $data['google_product_category'] = $form_data['google_product_category']; + $data['condition'] = $form_data['condition']; + $data['adult'] = $form_data['adult']; + $data['multipack'] = $form_data['multipack']; + $data['is_bundle'] = $form_data['is_bundle']; + $data['age_group'] = $form_data['age_group']; + $data['color'] = $form_data['color']; + $data['gender'] = $form_data['gender']; + $data['size_type'] = $form_data['size_type']; + $data['size_system'] = $form_data['size_system']; + $data['size'] = $form_data['size']; + + $json['body'] = $this->load->view('extension/advertise/google_popup_product', $data); + } else { + $json['title'] = $this->language->get('error_popup_not_found_title'); + $json['body'] = $this->language->get('error_popup_not_found_body'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function popup_issues() { + $json = array( + 'body' => '', + 'title' => '' + ); + + $this->language->load('extension/advertise/google'); + + $this->load->model('catalog/product'); + $this->load->model('extension/advertise/google'); + + $product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0; + + $product_issues = $this->model_extension_advertise_google->getProductIssues($product_id, $this->store_id); + + if ($product_issues !== NULL) { + $json['title'] = sprintf($this->language->get('text_popup_title_single'), $product_issues['name'], $product_issues['model']); + + $data['product_issues'] = $product_issues['entries']; + + $json['body'] = $this->load->view('extension/advertise/google_popup_issues', $data); + } else { + $json['title'] = $this->language->get('error_popup_not_found_title'); + $json['body'] = $this->language->get('error_popup_not_found_body'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function admin_link(&$route, &$data, &$template) { + if (!$this->user->hasPermission('access', 'extension/advertise/google')) { + return; + } + + foreach ($data['menus'] as &$menu) { + if ($menu['id'] == 'menu-marketing') { + $children = array(); + + $this->load->model('setting/store'); + + $children[] = array( + 'name' => $this->config->get('config_name'), + 'children' => array(), + 'href' => $this->url->link('extension/advertise/google', 'store_id=0&user_token=' . $this->session->data['user_token'], true) + ); + + foreach ($this->model_setting_store->getStores() as $store) { + $children[] = array( + 'name' => $store['name'], + 'children' => array(), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $store['store_id'] . '&user_token=' . $this->session->data['user_token'], true) + ); + } + + array_push($menu['children'], array( + 'name' => 'Google Shopping', + 'children' => $children, + 'href' => '' + )); + + return; + } + } + } + + public function addProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + $this->load->model('catalog/product'); + + foreach ($this->model_catalog_product->getProductStores($output) as $store_id) { + $this->model_extension_advertise_google->insertNewProducts(array($output), $store_id); + } + } + + public function copyProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + $this->load->model('catalog/product'); + + $final_product_id = $this->model_extension_advertise_google->getFinalProductId(); + + if (!empty($final_product_id)) { + foreach ($this->model_catalog_product->getProductStores($final_product_id) as $store_id) { + $this->model_extension_advertise_google->insertNewProducts(array($final_product_id), $store_id); + } + } + } + + public function deleteProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->deleteProducts(array((int)$args[0])); + } + + public function install() { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->createTables(); + $this->model_extension_advertise_google->createEvents(); + } + + public function uninstall() { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->dropTables(); + $this->model_extension_advertise_google->deleteEvents(); + } + + public function category_autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('extension/advertise/google'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'sort' => 'name', + 'order' => 'ASC', + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_extension_advertise_google->getCategories($filter_data, $this->store_id); + + foreach ($results as $result) { + $json[] = array( + 'category_id' => $result['category_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function getFilter($array) { + if (!empty($array)) { + return array( + 'filter_product_name' => $array['product_name'], + 'filter_product_model' => $array['product_model'], + 'filter_category_id' => $array['category_id'], + 'filter_is_modified' => $array['is_modified'], + 'filter_store_id' => $this->store_id + ); + } + + return array( + 'filter_store_id' => $this->store_id + ); + } + + protected function applyNewSettings($new_settings) { + $this->load->model('setting/setting'); + + $old_settings = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + $new_settings = array_merge($old_settings, $new_settings); + + $this->model_setting_setting->editSetting('advertise_google', $new_settings, $this->store_id); + + foreach ($new_settings as $key => $value) { + $this->setting->set($key, $value); + } + } + + protected function product(&$row) { + $this->load->config('googleshopping/googleshopping'); + + $this->load->model('tool/image'); + + if (!empty($row['image']) && file_exists(DIR_IMAGE . $row['image'])) { + $image = $this->model_tool_image->resize($row['image'], 50, 50); + } else { + $image = $this->model_tool_image->resize('no_image.png', 50, 50); + } + + return array( + 'product_advertise_google_id' => (int)$row['product_advertise_google_id'], + 'product_id' => (int)$row['product_id'], + 'image' => $image, + 'name' => htmlentities(html_entity_decode($row['name'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'), + 'model' => $row['model'], + 'impressions' => (int)$row['impressions'], + 'clicks' => (int)$row['clicks'], + 'conversions' => (int)$row['conversions'], + 'cost' => $this->googleshopping->currencyFormat($row['cost']), + 'conversion_value' => $this->googleshopping->currencyFormat($row['conversion_value']), + 'destination_status' => $row['destination_status'], + 'is_modified' => (bool)$row['is_modified'], + 'has_issues' => (bool)$row['has_issues'], + 'url_issues' => html_entity_decode($this->url->link('extension/advertise/google/popup_issues', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&product_id=' . $row['product_id'], true), ENT_QUOTES, 'UTF-8'), + 'campaigns' => $this->model_extension_advertise_google->getProductCampaigns((int)$row['product_id'], $this->store_id) + ); + } + + protected function getSettingValue($key, $default = null, $checkbox = false) { + if ($checkbox) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post[$key])) { + return $default; + } else { + return $this->setting->get($key); + } + } + + if (isset($this->request->post[$key])) { + return $this->request->post[$key]; + } else if ($this->setting->has($key)) { + return $this->setting->get($key); + } else { + return $default; + } + } + + protected function getValidationError($key) { + if (isset($this->error[$key])) { + return $this->error[$key]; + } else { + return ''; + } + } + + protected function validateSettings() { + $this->validatePermission(); + + if (empty($this->request->post['advertise_google_status'])) { + return true; + } + + if (!empty($this->request->post['advertise_google_cron_email_status'])) { + if (!filter_var($this->request->post['advertise_google_cron_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['cron_email'] = $this->language->get('error_invalid_email'); + } + } + + if (empty($this->request->post['advertise_google_cron_acknowledge'])) { + $this->error['cron_acknowledge'] = $this->language->get('error_cron_acknowledge'); + } + + if ($this->error && empty($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_form'); + } + + return !$this->error; + } + + protected function validateShippingAndTaxes() { + $this->validatePermission(); + + if (empty($this->request->post['advertise_google_shipping_taxes']['min_transit_time']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['min_transit_time']) || (int)$this->request->post['advertise_google_shipping_taxes']['min_transit_time'] < 0) { + $this->error['min_transit_time'] = $this->language->get('error_min_transit_time'); + } else if (empty($this->request->post['advertise_google_shipping_taxes']['max_transit_time']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['max_transit_time']) || (int)$this->request->post['advertise_google_shipping_taxes']['max_transit_time'] < (int)$this->request->post['advertise_google_shipping_taxes']['min_transit_time']) { + $this->error['max_transit_time'] = $this->language->get('error_max_transit_time'); + } + + switch ($this->request->post['advertise_google_shipping_taxes']['shipping_type']) { + case 'flat' : + if (!isset($this->request->post['advertise_google_shipping_taxes']['flat_rate']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['flat_rate']) || (float)$this->request->post['advertise_google_shipping_taxes']['flat_rate'] <= 0) { + $this->error['flat_rate'] = $this->language->get('error_flat_rate'); + } + break; + case 'carrier' : + if (empty($this->request->post['advertise_google_shipping_taxes']['carrier'])) { + $this->error['warning'] = $this->language->get('error_carrier'); + } + + if (empty($this->request->post['advertise_google_shipping_taxes']['carrier_postcode'])) { + $this->error['carrier_postcode'] = $this->language->get('error_carrier_postcode'); + } + + if (!isset($this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage']) || (float)$this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage'] < 0 || (float)$this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage'] > 100) { + $this->error['carrier_price_percentage'] = $this->language->get('error_carrier_price_percentage'); + } + break; + } + + switch ($this->request->post['advertise_google_shipping_taxes']['tax_type']) { + case 'usa' : + if (empty($this->request->post['advertise_google_shipping_taxes']['tax'])) { + $this->error['warning'] = $this->language->get('error_tax'); + } + break; + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateMapping() { + $this->validatePermission(); + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateProduct($required_fields) { + if (!$this->user->hasPermission('modify', 'extension/advertise/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + foreach ($required_fields as $key => $requirements) { + if (empty($requirements['selected_field']) && (!isset($this->request->post['form'][$key]) || $this->request->post['form'][$key] == '')) { + $this->error[$key] = $this->language->get('error_field_no_value'); + } else if (!empty($requirements['selected_field'])) { + foreach ($requirements['selected_field'] as $dependency => $values) { + if (in_array($this->request->post['form'][$dependency], $values) && (!isset($this->request->post['form'][$key]) || $this->request->post['form'][$key] == '')) { + $this->error[$key] = $this->language->get('error_field_no_value'); + } + } + } + } + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validatePermission() { + if (!$this->user->hasPermission('modify', 'extension/advertise/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + protected function validateCampaign() { + $this->validatePermission(); + + $this->load->model('extension/advertise/google'); + + $targets = $this->googleshopping->getTargets($this->store_id); + + if (empty($targets)) { + $this->error['warning'] = $this->language->get('error_no_targets'); + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateConnect() { + $this->validatePermission(); + + if (!isset($this->request->post['advertise_google_app_id']) || trim($this->request->post['advertise_google_app_id']) == '') { + $this->error['app_id'] = $this->language->get('error_empty_app_id'); + } else if ($this->model_extension_advertise_google->isAppIdUsed($this->request->post['advertise_google_app_id'], $this->store_id)) { + $this->error['app_id'] = $this->language->get('error_used_app_id'); + } + + if (!isset($this->request->post['advertise_google_app_secret']) || trim($this->request->post['advertise_google_app_secret']) == '') { + $this->error['app_secret'] = $this->language->get('error_empty_app_secret'); + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateTarget() { + $this->validatePermission(); + + if (!isset($this->request->post['budget']) || !is_numeric($this->request->post['budget']) || (float)$this->request->post['budget'] < 5) { + $this->error['budget'] = $this->language->get('error_budget'); + } + + if (empty($this->request->post['feed']) || !is_array($this->request->post['feed'])) { + $this->error['feed'] = $this->language->get('error_empty_feed'); + } else { + foreach ($this->request->post['feed'] as $feed) { + if (empty($feed['language']) || empty($feed['currency'])) { + $this->error['feed'] = $this->language->get('error_invalid_feed'); + break; + } + } + } + + if (empty($this->request->post['country'])) { + $this->error['country'] = $this->language->get('error_empty_country'); + } + + if (empty($this->request->post['campaign_name']) || trim($this->request->post['campaign_name']) == '') { + $this->error['campaign_name'] = $this->language->get('error_empty_campaign_name'); + } else { + $disallowed_names = []; + + $this->load->model('extension/advertise/google'); + + foreach ($this->googleshopping->getTargets($this->store_id) as $existing_target) { + if (isset($this->request->get['advertise_google_target_id']) && $existing_target['target_id'] == $this->request->get['advertise_google_target_id']) { + // Ignore this target as it is currntly being edited + continue; + } + + $disallowed_names[] = strtolower(str_replace(',', ',', trim($existing_target['campaign_name']))); + } + + if (in_array(trim(strtolower($this->request->post['campaign_name'])), $disallowed_names)) { + $this->error['campaign_name'] = $this->language->get('error_campaign_name_in_use'); + } + + if (strtolower(trim($this->request->post['campaign_name'])) == 'total') { + $this->error['campaign_name'] = $this->language->get('error_campaign_name_total'); + } + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/analytics/google.php b/public/admin/controller/extension/analytics/google.php new file mode 100644 index 0000000..77c39e9 --- /dev/null +++ b/public/admin/controller/extension/analytics/google.php @@ -0,0 +1,85 @@ +<?php +class ControllerExtensionAnalyticsGoogle extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/analytics/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('analytics_google', $this->request->post, $this->request->get['store_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/analytics/google', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true) + ); + + $data['action'] = $this->url->link('extension/analytics/google', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['analytics_google_code'])) { + $data['analytics_google_code'] = $this->request->post['analytics_google_code']; + } else { + $data['analytics_google_code'] = $this->model_setting_setting->getSettingValue('analytics_google_code', $this->request->get['store_id']); + } + + if (isset($this->request->post['analytics_google_status'])) { + $data['analytics_google_status'] = $this->request->post['analytics_google_status']; + } else { + $data['analytics_google_status'] = $this->model_setting_setting->getSettingValue('analytics_google_status', $this->request->get['store_id']); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/analytics/google', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/analytics/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['analytics_google_code']) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/captcha/basic.php b/public/admin/controller/extension/captcha/basic.php new file mode 100644 index 0000000..f975ba3 --- /dev/null +++ b/public/admin/controller/extension/captcha/basic.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionCaptchaBasic extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/captcha/basic'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('captcha_basic', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/captcha/basic', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/captcha/basic', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true); + + if (isset($this->request->post['captcha_basic_status'])) { + $data['captcha_basic_status'] = $this->request->post['captcha_basic_status']; + } else { + $data['captcha_basic_status'] = $this->config->get('captcha_basic_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/captcha/basic', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/captcha/basic')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/captcha/google.php b/public/admin/controller/extension/captcha/google.php new file mode 100644 index 0000000..e6a98c6 --- /dev/null +++ b/public/admin/controller/extension/captcha/google.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionCaptchaGoogle extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/captcha/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('captcha_google', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/captcha/google', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/captcha/google', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true); + + if (isset($this->request->post['captcha_google_key'])) { + $data['captcha_google_key'] = $this->request->post['captcha_google_key']; + } else { + $data['captcha_google_key'] = $this->config->get('captcha_google_key'); + } + + if (isset($this->request->post['captcha_google_secret'])) { + $data['captcha_google_secret'] = $this->request->post['captcha_google_secret']; + } else { + $data['captcha_google_secret'] = $this->config->get('captcha_google_secret'); + } + + if (isset($this->request->post['captcha_google_status'])) { + $data['captcha_google_status'] = $this->request->post['captcha_google_status']; + } else { + $data['captcha_google_status'] = $this->config->get('captcha_google_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/captcha/google', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/captcha/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['captcha_google_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['captcha_google_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/dashboard/activity.php b/public/admin/controller/extension/dashboard/activity.php new file mode 100644 index 0000000..68d71fe --- /dev/null +++ b/public/admin/controller/extension/dashboard/activity.php @@ -0,0 +1,120 @@ +<?php +class ControllerExtensionDashboardActivity extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/activity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_activity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/activity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/activity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_activity_width'])) { + $data['dashboard_activity_width'] = $this->request->post['dashboard_activity_width']; + } else { + $data['dashboard_activity_width'] = $this->config->get('dashboard_activity_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_activity_status'])) { + $data['dashboard_activity_status'] = $this->request->post['dashboard_activity_status']; + } else { + $data['dashboard_activity_status'] = $this->config->get('dashboard_activity_status'); + } + + if (isset($this->request->post['dashboard_activity_sort_order'])) { + $data['dashboard_activity_sort_order'] = $this->request->post['dashboard_activity_sort_order']; + } else { + $data['dashboard_activity_sort_order'] = $this->config->get('dashboard_activity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/activity_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/activity')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/activity'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['activities'] = array(); + + $this->load->model('extension/dashboard/activity'); + + $results = $this->model_extension_dashboard_activity->getActivities(); + + foreach ($results as $result) { + $comment = vsprintf($this->language->get('text_activity_' . $result['key']), json_decode($result['data'], true)); + + $find = array( + 'customer_id=', + 'order_id=', + 'return_id=' + ); + + $replace = array( + $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=', true), + $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=', true), + $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=', true) + ); + + $data['activities'][] = array( + 'comment' => str_replace($find, $replace, $comment), + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + return $this->load->view('extension/dashboard/activity_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/dashboard/chart.php b/public/admin/controller/extension/dashboard/chart.php new file mode 100644 index 0000000..f361a09 --- /dev/null +++ b/public/admin/controller/extension/dashboard/chart.php @@ -0,0 +1,197 @@ +<?php +class ControllerExtensionDashboardChart extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/chart'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_chart', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_chart_width'])) { + $data['dashboard_chart_width'] = $this->request->post['dashboard_chart_width']; + } else { + $data['dashboard_chart_width'] = $this->config->get('dashboardchart_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_chart_status'])) { + $data['dashboard_chart_status'] = $this->request->post['dashboard_chart_status']; + } else { + $data['dashboard_chart_status'] = $this->config->get('dashboard_chart_status'); + } + + if (isset($this->request->post['dashboard_chart_sort_order'])) { + $data['dashboard_chart_sort_order'] = $this->request->post['dashboard_chart_sort_order']; + } else { + $data['dashboard_chart_sort_order'] = $this->config->get('dashboard_chart_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/chart_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/chart')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/chart'); + + $data['user_token'] = $this->session->data['user_token']; + + return $this->load->view('extension/dashboard/chart_info', $data); + } + + public function chart() { + $this->load->language('extension/dashboard/chart'); + + $json = array(); + + $this->load->model('extension/dashboard/chart'); + + $json['order'] = array(); + $json['customer'] = array(); + $json['xaxis'] = array(); + + $json['order']['label'] = $this->language->get('text_order'); + $json['customer']['label'] = $this->language->get('text_customer'); + $json['order']['data'] = array(); + $json['customer']['data'] = array(); + + if (isset($this->request->get['range'])) { + $range = $this->request->get['range']; + } else { + $range = 'day'; + } + + switch ($range) { + default: + case 'day': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByDay(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByDay(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 0; $i < 24; $i++) { + $json['xaxis'][] = array($i, $i); + } + break; + case 'week': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByWeek(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByWeek(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + $date_start = strtotime('-' . date('w') . ' days'); + + for ($i = 0; $i < 7; $i++) { + $date = date('Y-m-d', $date_start + ($i * 86400)); + + $json['xaxis'][] = array(date('w', strtotime($date)), date('D', strtotime($date))); + } + break; + case 'month': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByMonth(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByMonth(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 1; $i <= date('t'); $i++) { + $date = date('Y') . '-' . date('m') . '-' . $i; + + $json['xaxis'][] = array(date('j', strtotime($date)), date('d', strtotime($date))); + } + break; + case 'year': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByYear(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByYear(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 1; $i <= 12; $i++) { + $json['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i))); + } + break; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/dashboard/customer.php b/public/admin/controller/extension/dashboard/customer.php new file mode 100644 index 0000000..e5054d3 --- /dev/null +++ b/public/admin/controller/extension/dashboard/customer.php @@ -0,0 +1,124 @@ +<?php +class ControllerExtensionDashboardCustomer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_customer', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/customer', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/customer', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_customer_width'])) { + $data['dashboard_customer_width'] = $this->request->post['dashboard_customer_width']; + } else { + $data['dashboard_customer_width'] = $this->config->get('dashboard_customer_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_customer_status'])) { + $data['dashboard_customer_status'] = $this->request->post['dashboard_customer_status']; + } else { + $data['dashboard_customer_status'] = $this->config->get('dashboard_customer_status'); + } + + if (isset($this->request->post['dashboard_customer_sort_order'])) { + $data['dashboard_customer_sort_order'] = $this->request->post['dashboard_customer_sort_order']; + } else { + $data['dashboard_customer_sort_order'] = $this->config->get('dashboard_customer_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/customer_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/customer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/customer'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('customer/customer'); + + $today = $this->model_customer_customer->getTotalCustomers(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_customer_customer->getTotalCustomers(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && $today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $customer_total = $this->model_customer_customer->getTotalCustomers(); + + if ($customer_total > 1000000000000) { + $data['total'] = round($customer_total / 1000000000000, 1) . 'T'; + } elseif ($customer_total > 1000000000) { + $data['total'] = round($customer_total / 1000000000, 1) . 'B'; + } elseif ($customer_total > 1000000) { + $data['total'] = round($customer_total / 1000000, 1) . 'M'; + } elseif ($customer_total > 1000) { + $data['total'] = round($customer_total / 1000, 1) . 'K'; + } else { + $data['total'] = $customer_total; + } + + $data['customer'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/customer_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/map.php b/public/admin/controller/extension/dashboard/map.php new file mode 100644 index 0000000..0e19331 --- /dev/null +++ b/public/admin/controller/extension/dashboard/map.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionDashboardMap extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/map'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_map', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/map', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/map', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_map_width'])) { + $data['dashboard_map_width'] = $this->request->post['dashboard_map_width']; + } else { + $data['dashboard_map_width'] = $this->config->get('dashboard_map_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_map_status'])) { + $data['dashboard_map_status'] = $this->request->post['dashboard_map_status']; + } else { + $data['dashboard_map_status'] = $this->config->get('dashboard_map_status'); + } + + if (isset($this->request->post['dashboard_map_sort_order'])) { + $data['dashboard_map_sort_order'] = $this->request->post['dashboard_map_sort_order']; + } else { + $data['dashboard_map_sort_order'] = $this->config->get('dashboard_map_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/map_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/map')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/map'); + + $data['user_token'] = $this->session->data['user_token']; + + return $this->load->view('extension/dashboard/map_info', $data); + } + + public function map() { + $json = array(); + + $this->load->model('extension/dashboard/map'); + + $results = $this->model_extension_dashboard_map->getTotalOrdersByCountry(); + + foreach ($results as $result) { + $json[strtolower($result['iso_code_2'])] = array( + 'total' => $result['total'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')) + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/dashboard/online.php b/public/admin/controller/extension/dashboard/online.php new file mode 100644 index 0000000..4bb1ff7 --- /dev/null +++ b/public/admin/controller/extension/dashboard/online.php @@ -0,0 +1,113 @@ +<?php +class ControllerExtensionDashboardOnline extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/online'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_online', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/online', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/online', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_online_width'])) { + $data['dashboard_online_width'] = $this->request->post['dashboard_online_width']; + } else { + $data['dashboard_online_width'] = $this->config->get('dashboard_online_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_online_status'])) { + $data['dashboard_online_status'] = $this->request->post['dashboard_online_status']; + } else { + $data['dashboard_online_status'] = $this->config->get('dashboard_online_status'); + } + + if (isset($this->request->post['dashboard_online_sort_order'])) { + $data['dashboard_online_sort_order'] = $this->request->post['dashboard_online_sort_order']; + } else { + $data['dashboard_online_sort_order'] = $this->config->get('dashboard_online_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/online_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/online')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/online'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('extension/dashboard/online'); + + // Customers Online + $online_total = $this->model_extension_dashboard_online->getTotalOnline(); + + if ($online_total > 1000000000000) { + $data['total'] = round($online_total / 1000000000000, 1) . 'T'; + } elseif ($online_total > 1000000000) { + $data['total'] = round($online_total / 1000000000, 1) . 'B'; + } elseif ($online_total > 1000000) { + $data['total'] = round($online_total / 1000000, 1) . 'M'; + } elseif ($online_total > 1000) { + $data['total'] = round($online_total / 1000, 1) . 'K'; + } else { + $data['total'] = $online_total; + } + + $data['online'] = $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/online_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/order.php b/public/admin/controller/extension/dashboard/order.php new file mode 100644 index 0000000..3383fe3 --- /dev/null +++ b/public/admin/controller/extension/dashboard/order.php @@ -0,0 +1,124 @@ +<?php +class ControllerExtensionDashboardOrder extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_order_width'])) { + $data['dashboard_order_width'] = $this->request->post['dashboard_order_width']; + } else { + $data['dashboard_order_width'] = $this->config->get('dashboard_order_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_order_status'])) { + $data['dashboard_order_status'] = $this->request->post['dashboard_order_status']; + } else { + $data['dashboard_order_status'] = $this->config->get('dashboard_order_status'); + } + + if (isset($this->request->post['dashboard_order_sort_order'])) { + $data['dashboard_order_sort_order'] = $this->request->post['dashboard_order_sort_order']; + } else { + $data['dashboard_order_sort_order'] = $this->config->get('dashboard_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/order'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('sale/order'); + + $today = $this->model_sale_order->getTotalOrders(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_sale_order->getTotalOrders(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && $today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $order_total = $this->model_sale_order->getTotalOrders(); + + if ($order_total > 1000000000000) { + $data['total'] = round($order_total / 1000000000000, 1) . 'T'; + } elseif ($order_total > 1000000000) { + $data['total'] = round($order_total / 1000000000, 1) . 'B'; + } elseif ($order_total > 1000000) { + $data['total'] = round($order_total / 1000000, 1) . 'M'; + } elseif ($order_total > 1000) { + $data['total'] = round($order_total / 1000, 1) . 'K'; + } else { + $data['total'] = $order_total; + } + + $data['order'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/order_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/recent.php b/public/admin/controller/extension/dashboard/recent.php new file mode 100644 index 0000000..45063c7 --- /dev/null +++ b/public/admin/controller/extension/dashboard/recent.php @@ -0,0 +1,118 @@ +<?php +class ControllerExtensionDashboardRecent extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/recent'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_recent', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/recent', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/recent', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_recent_width'])) { + $data['dashboard_recent_width'] = $this->request->post['dashboard_recent_width']; + } else { + $data['dashboard_recent_width'] = $this->config->get('dashboard_recent_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_recent_status'])) { + $data['dashboard_recent_status'] = $this->request->post['dashboard_recent_status']; + } else { + $data['dashboard_recent_status'] = $this->config->get('dashboard_recent_status'); + } + + if (isset($this->request->post['dashboard_recent_sort_order'])) { + $data['dashboard_recent_sort_order'] = $this->request->post['dashboard_recent_sort_order']; + } else { + $data['dashboard_recent_sort_order'] = $this->config->get('dashboard_recent_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/recent_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/recent')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/recent'); + + $data['user_token'] = $this->session->data['user_token']; + + // Last 5 Orders + $data['orders'] = array(); + + $filter_data = array( + 'sort' => 'o.date_added', + 'order' => 'DESC', + 'start' => 0, + 'limit' => 5 + ); + + $this->load->model('sale/order'); + + $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['order_status'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']), + 'view' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'], true), + ); + } + + return $this->load->view('extension/dashboard/recent_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/sale.php b/public/admin/controller/extension/dashboard/sale.php new file mode 100644 index 0000000..887079c --- /dev/null +++ b/public/admin/controller/extension/dashboard/sale.php @@ -0,0 +1,123 @@ +<?php +class ControllerExtensionDashboardSale extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/sale'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_sale', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/sale', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/sale', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_sale_width'])) { + $data['dashboard_sale_width'] = $this->request->post['dashboard_sale_width']; + } else { + $data['dashboard_sale_width'] = $this->config->get('dashboard_sale_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_sale_status'])) { + $data['dashboard_sale_status'] = $this->request->post['dashboard_sale_status']; + } else { + $data['dashboard_sale_status'] = $this->config->get('dashboard_sale_status'); + } + + if (isset($this->request->post['dashboard_sale_sort_order'])) { + $data['dashboard_sale_sort_order'] = $this->request->post['dashboard_sale_sort_order']; + } else { + $data['dashboard_sale_sort_order'] = $this->config->get('dashboard_sale_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/sale_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/sale')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/sale'); + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('extension/dashboard/sale'); + + $today = $this->model_extension_dashboard_sale->getTotalSales(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_extension_dashboard_sale->getTotalSales(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && (int)$today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $sale_total = $this->model_extension_dashboard_sale->getTotalSales(); + + if ($sale_total > 1000000000000) { + $data['total'] = round($sale_total / 1000000000000, 1) . 'T'; + } elseif ($sale_total > 1000000000) { + $data['total'] = round($sale_total / 1000000000, 1) . 'B'; + } elseif ($sale_total > 1000000) { + $data['total'] = round($sale_total / 1000000, 1) . 'M'; + } elseif ($sale_total > 1000) { + $data['total'] = round($sale_total / 1000, 1) . 'K'; + } else { + $data['total'] = round($sale_total); + } + + $data['sale'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/sale_info', $data); + } +} diff --git a/public/admin/controller/extension/extension/advertise.php b/public/admin/controller/extension/extension/advertise.php new file mode 100644 index 0000000..0d8689e --- /dev/null +++ b/public/admin/controller/extension/extension/advertise.php @@ -0,0 +1,134 @@ +<?php +class ControllerExtensionExtensionAdvertise extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('advertise', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/advertise/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/advertise/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'advertise/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'advertise/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('advertise', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('advertise'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/advertise/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/advertise/' . $value . '.php')) { + $this->model_setting_extension->uninstall('advertise', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/advertise/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/advertise/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('advertise_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('advertise_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/advertise/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/advertise/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $this->response->setOutput($this->load->view('extension/extension/advertise', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/advertise')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/analytics.php b/public/admin/controller/extension/extension/analytics.php new file mode 100644 index 0000000..74bff33 --- /dev/null +++ b/public/admin/controller/extension/extension/analytics.php @@ -0,0 +1,136 @@ +<?php +class ControllerExtensionExtensionAnalytics extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('analytics', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/analytics/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/analytics/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'analytics/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'analytics/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/analytics/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('analytics', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/analytics/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('analytics'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/analytics/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/analytics/' . $value . '.php')) { + $this->model_setting_extension->uninstall('analytics', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/analytics/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/analytics/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/analytics/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('analytics_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/analytics/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('analytics_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/analytics/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/analytics/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/analytics', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/analytics')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/captcha.php b/public/admin/controller/extension/extension/captcha.php new file mode 100644 index 0000000..846ad1c --- /dev/null +++ b/public/admin/controller/extension/extension/captcha.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionExtensionCaptcha extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('captcha', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/captcha/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/captcha/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'captcha/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'captcha/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/captcha/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('captcha', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/captcha/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('captcha'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/captcha/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/captcha/' . $value . '.php')) { + $this->model_setting_extension->uninstall('captcha', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/captcha/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/captcha/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title') . (($extension == $this->config->get('config_captcha')) ? $this->language->get('text_default') : null), + 'status' => $this->config->get('captcha_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/captcha/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/captcha/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/captcha/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/captcha', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/captcha')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/dashboard.php b/public/admin/controller/extension/extension/dashboard.php new file mode 100644 index 0000000..d400418 --- /dev/null +++ b/public/admin/controller/extension/extension/dashboard.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionExtensionDashboard extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('dashboard', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/dashboard/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/dashboard/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/dashboard/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('dashboard', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/dashboard/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('dashboard'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/dashboard/' . $value . '.php')) { + $this->model_setting_extension->uninstall('dashboard', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/dashboard/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/dashboard/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'width' => $this->config->get('dashboard_' . $extension . '_width'), + 'status' => $this->config->get('dashboard_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('dashboard_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/dashboard/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/dashboard/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/dashboard/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/dashboard', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/dashboard')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/feed.php b/public/admin/controller/extension/extension/feed.php new file mode 100644 index 0000000..8dc1c94 --- /dev/null +++ b/public/admin/controller/extension/extension/feed.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionExtensionFeed extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('feed', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/feed/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/feed/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/feed/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('feed', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/feed/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('feed'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/feed/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/feed/' . $value . '.php')) { + $this->model_setting_extension->uninstall('feed', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/feed/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/feed/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('feed_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/feed/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/feed/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/feed/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/feed', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/feed')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/fraud.php b/public/admin/controller/extension/extension/fraud.php new file mode 100644 index 0000000..8a4b97b --- /dev/null +++ b/public/admin/controller/extension/extension/fraud.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionExtensionFraud extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('fraud', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/fraud/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/fraud/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/fraud/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('fraud', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/fraud/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('fraud'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/fraud/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/fraud/' . $value . '.php')) { + $this->model_setting_extension->uninstall('fraud', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/fraud/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/fraud/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('fraud_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/fraud/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/fraud/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/fraud/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/fraud', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/fraud')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/menu.php b/public/admin/controller/extension/extension/menu.php new file mode 100644 index 0000000..d490606 --- /dev/null +++ b/public/admin/controller/extension/extension/menu.php @@ -0,0 +1,121 @@ +<?php +class ControllerExtensionExtensionMenu extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('menu', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/menu/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/menu/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/menu/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('menu', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/menu/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + $data['text_layout'] = sprintf($this->language->get('text_layout'), $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('menu'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/menu/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/menu/' . $value . '.php')) { + $this->model_setting_extension->uninstall('menu', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/menu/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/menu/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('menu_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/menu/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/menu/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/menu/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $sort_order = array(); + + foreach ($data['extensions'] as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $data['extensions']); + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/menu', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/menu')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/module.php b/public/admin/controller/extension/extension/module.php new file mode 100644 index 0000000..a76d202 --- /dev/null +++ b/public/admin/controller/extension/extension/module.php @@ -0,0 +1,191 @@ +<?php +class ControllerExtensionExtensionModule extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->model_setting_extension->install('module', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/module/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } else { + $this->session->data['error'] = $this->error['warning']; + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('module', $this->request->get['extension']); + + $this->model_setting_module->deleteModulesByCode($this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/module/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function add() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->load->language('module' . '/' . $this->request->get['extension']); + + $this->model_setting_module->addModule($this->request->get['extension'], $this->language->get('heading_title')); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function delete() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if (isset($this->request->get['module_id']) && $this->validate()) { + $this->model_setting_module->deleteModule($this->request->get['module_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + $data['text_layout'] = sprintf($this->language->get('text_layout'), $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('module'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/module/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/module/' . $value . '.php')) { + $this->model_setting_extension->uninstall('module', $value); + + unset($extensions[$key]); + + $this->model_setting_module->deleteModulesByCode($value); + } + } + + $data['extensions'] = array(); + + // Create a new language container so we don't pollute the current one + $language = new Language($this->config->get('config_language')); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/module/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/module/' . $extension, 'extension'); + + $module_data = array(); + + $modules = $this->model_setting_module->getModulesByCode($extension); + + foreach ($modules as $module) { + if ($module['setting']) { + $setting_info = json_decode($module['setting'], true); + } else { + $setting_info = array(); + } + + $module_data[] = array( + 'module_id' => $module['module_id'], + 'name' => $module['name'], + 'status' => (isset($setting_info['status']) && $setting_info['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'edit' => $this->url->link('extension/module/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id'], true), + 'delete' => $this->url->link('extension/extension/module/delete', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id'], true) + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('module_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'module' => $module_data, + 'install' => $this->url->link('extension/extension/module/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/module/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/module/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $sort_order = array(); + + foreach ($data['extensions'] as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $data['extensions']); + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/module', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/payment.php b/public/admin/controller/extension/extension/payment.php new file mode 100644 index 0000000..e73d3d5 --- /dev/null +++ b/public/admin/controller/extension/extension/payment.php @@ -0,0 +1,123 @@ +<?php +class ControllerExtensionExtensionPayment extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('payment', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/payment/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/payment/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/payment/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('payment', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/payment/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('payment'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/payment/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/payment/' . $value . '.php')) { + $this->model_setting_extension->uninstall('payment', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/payment/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/payment/' . $extension, 'extension'); + + $text_link = $this->language->get('extension')->get('text_' . $extension); + + if ($text_link != 'text_' . $extension) { + $link = $text_link; + } else { + $link = ''; + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'link' => $link, + 'status' => $this->config->get('payment_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('payment_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/payment/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/payment/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/payment/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/payment', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/payment')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/promotion.php b/public/admin/controller/extension/extension/promotion.php new file mode 100644 index 0000000..aeef853 --- /dev/null +++ b/public/admin/controller/extension/extension/promotion.php @@ -0,0 +1,23 @@ +<?php +class ControllerExtensionExtensionPromotion extends Controller { + public function index() { + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_URL, OPENCART_SERVER . 'index.php?route=api/promotion&type=' . substr($this->request->get['route'], strrpos($this->request->get['route'], '/') + 1)); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + + $response = curl_exec($curl); + + curl_close($curl); + + if ($response) { + return $response; + } else { + return ''; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/report.php b/public/admin/controller/extension/extension/report.php new file mode 100644 index 0000000..685604c --- /dev/null +++ b/public/admin/controller/extension/extension/report.php @@ -0,0 +1,112 @@ +<?php +class ControllerExtensionExtensionReport extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('report', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/report/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/report/' . $this->request->get['extension']); + + $this->load->controller('extension/report/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('report', $this->request->get['extension']); + + $this->load->controller('extension/report/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('report'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/report/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/report/' . $value . '.php')) { + $this->model_setting_extension->uninstall('report', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/report/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/report/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('report_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('report_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/report/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/report/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/report/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/report', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/report')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/shipping.php b/public/admin/controller/extension/extension/shipping.php new file mode 100644 index 0000000..55feb41 --- /dev/null +++ b/public/admin/controller/extension/extension/shipping.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionExtensionShipping extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('shipping', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/shipping/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/shipping/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/shipping/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('shipping', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/shipping/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('shipping'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/shipping/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/shipping/' . $value . '.php')) { + $this->model_setting_extension->uninstall('shipping', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/shipping/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('shipping_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('shipping_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/shipping/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/shipping/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/shipping/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/shipping', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/theme.php b/public/admin/controller/extension/extension/theme.php new file mode 100644 index 0000000..813f368 --- /dev/null +++ b/public/admin/controller/extension/extension/theme.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionExtensionTheme extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/theme'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('theme', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/theme/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/theme/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/theme/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/theme'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('theme', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/theme/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('theme'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/theme/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/theme/' . $value . '.php')) { + $this->model_setting_extension->uninstall('theme', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/theme/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/theme/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/theme/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('theme_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/theme/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('theme_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/theme/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/theme/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/theme', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/total.php b/public/admin/controller/extension/extension/total.php new file mode 100644 index 0000000..ad27ff9 --- /dev/null +++ b/public/admin/controller/extension/extension/total.php @@ -0,0 +1,112 @@ +<?php +class ControllerExtensionExtensionTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('total', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/total/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/total/' . $this->request->get['extension']); + + $this->load->controller('extension/total/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('total', $this->request->get['extension']); + + $this->load->controller('extension/total/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + 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'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('total'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/total/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/total/' . $value . '.php')) { + $this->model_setting_extension->uninstall('total', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/total/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/total/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('total_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('total_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/total/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/total/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/total/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/feed/google_base.php b/public/admin/controller/extension/feed/google_base.php new file mode 100644 index 0000000..ff88d41 --- /dev/null +++ b/public/admin/controller/extension/feed/google_base.php @@ -0,0 +1,243 @@ +<?php +class ControllerExtensionFeedGoogleBase extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/feed/google_base'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('feed_google_base', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/feed/google_base', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/feed/google_base', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['data_feed'] = HTTP_CATALOG . 'index.php?route=extension/feed/google_base'; + + if (isset($this->request->post['feed_google_base_status'])) { + $data['feed_google_base_status'] = $this->request->post['feed_google_base_status']; + } else { + $data['feed_google_base_status'] = $this->config->get('feed_google_base_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/feed/google_base', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->install(); + } + + public function uninstall() { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->uninstall(); + } + + public function import() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_name'])) { + // Sanitize the filename + $filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')); + + // Allowed file extension types + if (utf8_strtolower(utf8_substr(strrchr($filename, '.'), 1)) != 'txt') { + $json['error'] = $this->language->get('error_filetype'); + } + + // Allowed file mime types + if ($this->request->files['file']['type'] != 'text/plain') { + $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) { + $json['success'] = $this->language->get('text_success'); + + $this->load->model('extension/feed/google_base'); + + // Get the contents of the uploaded file + $content = file_get_contents($this->request->files['file']['tmp_name']); + + $this->model_extension_feed_google_base->import($content); + + unlink($this->request->files['file']['tmp_name']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function category() { + $this->load->language('extension/feed/google_base'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['google_base_categories'] = array(); + + $this->load->model('extension/feed/google_base'); + + $results = $this->model_extension_feed_google_base->getCategories(($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['google_base_categories'][] = array( + 'google_base_category_id' => $result['google_base_category_id'], + 'google_base_category' => $result['google_base_category'], + 'category_id' => $result['category_id'], + 'category' => $result['category'] + ); + } + + $category_total = $this->model_extension_feed_google_base->getTotalCategories(); + + $pagination = new Pagination(); + $pagination->total = $category_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('extension/feed/google_base/category', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($category_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($category_total - 10)) ? $category_total : ((($page - 1) * 10) + 10), $category_total, ceil($category_total / 10)); + + $this->response->setOutput($this->load->view('extension/feed/google_base_category', $data)); + } + + public function addCategory() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } elseif (!empty($this->request->post['google_base_category_id']) && !empty($this->request->post['category_id'])) { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->addCategory($this->request->post); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeCategory() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->deleteCategory($this->request->post['category_id']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('extension/feed/google_base'); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + $filter_data = array( + 'filter_name' => html_entity_decode($filter_name, ENT_QUOTES, 'UTF-8'), + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_extension_feed_google_base->getGoogleBaseCategories($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'google_base_category_id' => $result['google_base_category_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/feed/google_sitemap.php b/public/admin/controller/extension/feed/google_sitemap.php new file mode 100644 index 0000000..38c96dc --- /dev/null +++ b/public/admin/controller/extension/feed/google_sitemap.php @@ -0,0 +1,69 @@ +<?php +class ControllerExtensionFeedGoogleSitemap extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/feed/google_sitemap'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('feed_google_sitemap', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/feed/google_sitemap', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/feed/google_sitemap', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true); + + if (isset($this->request->post['feed_google_sitemap_status'])) { + $data['feed_google_sitemap_status'] = $this->request->post['feed_google_sitemap_status']; + } else { + $data['feed_google_sitemap_status'] = $this->config->get('feed_google_sitemap_status'); + } + + $data['data_feed'] = HTTP_CATALOG . 'index.php?route=extension/feed/google_sitemap'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/feed/google_sitemap', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/feed/google_sitemap')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/feed/openbaypro.php b/public/admin/controller/extension/feed/openbaypro.php new file mode 100644 index 0000000..10e8994 --- /dev/null +++ b/public/admin/controller/extension/feed/openbaypro.php @@ -0,0 +1,48 @@ +<?php +class ControllerExtensionFeedOpenbaypro extends Controller { + private $error = array(); + + public function index() { + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/openbaypro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/setting'); + $this->load->model('setting/event'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'marketplace/openbay'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'marketplace/openbay'); + + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + $settings['feed_openbaypro_status'] = 1; + $settings['feed_openbaypro_language'] = "en_GB"; + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + + $this->model_setting_event->addEvent('openbay_product_del_after', 'admin/model/catalog/product/deleteProduct/after', 'marketplace/openbay/eventDeleteProduct'); + + $this->model_setting_event->addEvent('openbay_product_edit_after', 'admin/model/catalog/product/editProduct/after', 'marketplace/openbay/eventEditProduct'); + + $this->model_setting_event->addEvent('openbay_menu', 'admin/view/common/column_left/before', 'marketplace/openbay/eventMenu'); + } + + public function uninstall() { + $this->load->model('setting/setting'); + $this->load->model('setting/event'); + + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + $settings['feed_openbaypro_status'] = 0; + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + + $this->model_setting_event->deleteEventByCode('openbay_product_del_after'); + $this->model_setting_event->deleteEventByCode('openbay_product_edit_after'); + $this->model_setting_event->deleteEventByCode('openbay_menu'); + } +} diff --git a/public/admin/controller/extension/fraud/fraudlabspro.php b/public/admin/controller/extension/fraud/fraudlabspro.php new file mode 100644 index 0000000..c17eda0 --- /dev/null +++ b/public/admin/controller/extension/fraud/fraudlabspro.php @@ -0,0 +1,331 @@ +<?php +class ControllerExtensionFraudFraudLabsPro extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/fraudlabspro'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_fraudlabspro', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/fraudlabspro', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/fraudlabspro', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_fraudlabspro_key'])) { + $data['fraud_fraudlabspro_key'] = $this->request->post['fraud_fraudlabspro_key']; + } else { + $data['fraud_fraudlabspro_key'] = $this->config->get('fraud_fraudlabspro_key'); + } + + if (isset($this->request->post['fraud_fraudlabspro_score'])) { + $data['fraud_fraudlabspro_score'] = $this->request->post['fraud_fraudlabspro_score']; + } else { + $data['fraud_fraudlabspro_score'] = $this->config->get('fraud_fraudlabspro_score'); + } + + if (isset($this->request->post['fraud_fraudlabspro_order_status_id'])) { + $data['fraud_fraudlabspro_order_status_id'] = $this->request->post['fraud_fraudlabspro_order_status_id']; + } else { + $data['fraud_fraudlabspro_order_status_id'] = $this->config->get('fraud_fraudlabspro_order_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_review_status_id'])) { + $data['fraud_fraudlabspro_review_status_id'] = $this->request->post['fraud_fraudlabspro_review_status_id']; + } else { + $data['fraud_fraudlabspro_review_status_id'] = $this->config->get('fraud_fraudlabspro_review_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_approve_status_id'])) { + $data['fraud_fraudlabspro_approve_status_id'] = $this->request->post['fraud_fraudlabspro_approve_status_id']; + } else { + $data['fraud_fraudlabspro_approve_status_id'] = $this->config->get('fraud_fraudlabspro_approve_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_reject_status_id'])) { + $data['fraud_fraudlabspro_reject_status_id'] = $this->request->post['fraud_fraudlabspro_reject_status_id']; + } else { + $data['fraud_fraudlabspro_reject_status_id'] = $this->config->get('fraud_fraudlabspro_reject_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_simulate_ip'])) { + $data['fraud_fraudlabspro_simulate_ip'] = $this->request->post['fraud_fraudlabspro_simulate_ip']; + } else { + $data['fraud_fraudlabspro_simulate_ip'] = $this->config->get('fraud_fraudlabspro_simulate_ip'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_fraudlabspro_status'])) { + $data['fraud_fraudlabspro_status'] = $this->request->post['fraud_fraudlabspro_status']; + } else { + $data['fraud_fraudlabspro_status'] = $this->config->get('fraud_fraudlabspro_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/fraudlabspro', $data)); + } + + public function install() { + $this->load->model('extension/fraud/fraudlabspro'); + + $this->model_extension_fraud_fraudlabspro->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/fraudlabspro'); + + $this->model_extension_fraud_fraudlabspro->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/fraudlabspro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['fraud_fraudlabspro_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + public function order() { + $this->load->language('extension/fraud/fraudlabspro'); + + $this->load->model('extension/fraud/fraudlabspro'); + + // Action of the Approve/Reject button click + if (isset($_POST['flp_id'])){ + $flp_status = $_POST['new_status']; + $data['flp_status'] = $flp_status; + + //Feedback FLP status to server + $fraud_fraudlabspro_key = $this->config->get('fraud_fraudlabspro_key'); + + for($i=0; $i<3; $i++){ + $result = @file_get_contents('https://api.fraudlabspro.com/v1/order/feedback?key=' . $fraud_fraudlabspro_key . '&format=json&id=' . $_POST['flp_id'] . '&action=' . $flp_status); + + if($result) break; + } + + // Update fraud status into table + $this->db->query("UPDATE `" . DB_PREFIX . "fraudlabspro` SET fraudlabspro_status = '" . $this->db->escape($flp_status) . "' WHERE order_id = " . $this->db->escape($this->request->get['order_id'])); + + //Update history record + if (strtolower($flp_status) == 'approve'){ + $data_temp = array( + 'order_status_id'=>$this->config->get('fraud_fraudlabspro_approve_status_id'), + 'notify'=>0, + 'comment'=>'Approved using FraudLabs Pro.' + ); + + $this->model_extension_fraud_fraudlabspro->addOrderHistory($this->request->get['order_id'], $data_temp); + } + else if (strtolower($flp_status) == "reject"){ + $data_temp = array( + 'order_status_id'=>$this->config->get('fraud_fraudlabspro_reject_status_id'), + 'notify'=>0, + 'comment'=>'Rejected using FraudLabs Pro.' + ); + + $this->model_extension_fraud_fraudlabspro->addOrderHistory($this->request->get['order_id'], $data_temp); + } + } + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $fraud_info = $this->model_extension_fraud_fraudlabspro->getOrder($order_id); + + if ($fraud_info) { + if ($fraud_info['ip_address']) { + $data['flp_ip_address'] = $fraud_info['ip_address']; + } else { + $data['flp_ip_address'] = ''; + } + + if ($fraud_info['ip_netspeed']) { + $data['flp_ip_net_speed'] = $fraud_info['ip_netspeed']; + } else { + $data['flp_ip_net_speed'] = ''; + } + + if ($fraud_info['ip_isp_name']) { + $data['flp_ip_isp_name'] = $fraud_info['ip_isp_name']; + } else { + $data['flp_ip_isp_name'] = ''; + } + + if ($fraud_info['ip_usage_type']) { + $data['flp_ip_usage_type'] = $fraud_info['ip_usage_type']; + } else { + $data['flp_ip_usage_type'] = ''; + } + + if ($fraud_info['ip_domain']) { + $data['flp_ip_domain'] = $fraud_info['ip_domain']; + } else { + $data['flp_ip_domain'] = ''; + } + + if ($fraud_info['ip_timezone']) { + $data['flp_ip_time_zone'] = $fraud_info['ip_timezone']; + } else { + $data['flp_ip_time_zone'] = ''; + } + + if ($fraud_info['ip_country']) { + $data['flp_ip_location'] = $this->fix_case($fraud_info['ip_continent']) . ", " . $fraud_info['ip_country'] . ", " . $fraud_info['ip_region'] . ", " . $fraud_info['ip_city'] . " <a href=\"http://www.geolocation.com/" . $fraud_info['ip_address'] . "\" target=\"_blank\">[Map]</a>"; + } else { + $data['flp_ip_location'] = '-'; + } + + if ($fraud_info['distance_in_mile'] != '-') { + $data['flp_ip_distance'] = $fraud_info['distance_in_mile'] . " miles"; + } else { + $data['flp_ip_distance'] = ''; + } + + if ($fraud_info['ip_latitude']) { + $data['flp_ip_latitude'] = $fraud_info['ip_latitude']; + } else { + $data['flp_ip_latitude'] = ''; + } + + if ($fraud_info['ip_longitude']) { + $data['flp_ip_longitude'] = $fraud_info['ip_longitude']; + } else { + $data['flp_ip_longitude'] = ''; + } + + if ($fraud_info['is_high_risk_country']) { + $data['flp_risk_country'] = $fraud_info['is_high_risk_country']; + } else { + $data['flp_risk_country'] = ''; + } + + if ($fraud_info['is_free_email']) { + $data['flp_free_email'] = $fraud_info['is_free_email']; + } else { + $data['flp_free_email'] = ''; + } + + if ($fraud_info['is_address_ship_forward']) { + $data['flp_ship_forward'] = $fraud_info['is_address_ship_forward']; + } else { + $data['flp_ship_forward'] = ''; + } + + if ($fraud_info['is_proxy_ip_address']) { + $data['flp_using_proxy'] = $fraud_info['is_proxy_ip_address']; + } else { + $data['flp_using_proxy'] = ''; + } + + if ($fraud_info['is_bin_found']) { + $data['flp_bin_found'] = $fraud_info['is_bin_found']; + } else { + $data['flp_bin_found'] = ''; + } + + if ($fraud_info['is_email_blacklist']) { + $data['flp_email_blacklist'] = $fraud_info['is_email_blacklist']; + } else { + $data['flp_email_blacklist'] = ''; + } + + if ($fraud_info['is_credit_card_blacklist']) { + $data['flp_credit_card_blacklist'] = $fraud_info['is_credit_card_blacklist']; + } else { + $data['flp_credit_card_blacklist'] = ''; + } + + if ($fraud_info['fraudlabspro_score']) { + $data['flp_score'] = $fraud_info['fraudlabspro_score']; + } else { + $data['flp_score'] = ''; + } + + if ($fraud_info['fraudlabspro_status']) { + $data['flp_status'] = $fraud_info['fraudlabspro_status']; + } else { + $data['flp_status'] = ''; + } + + if ($fraud_info['fraudlabspro_message']) { + $data['flp_message'] = $fraud_info['fraudlabspro_message']; + } else { + $data['flp_message'] = ''; + } + + if ($fraud_info['fraudlabspro_id']) { + $data['flp_id'] = $fraud_info['fraudlabspro_id']; + $data['flp_link'] = $fraud_info['fraudlabspro_id']; + } else { + $data['flp_id'] = ''; + $data['flp_link'] = ''; + } + + if ($fraud_info['fraudlabspro_credits']) { + $data['flp_credits'] = $fraud_info['fraudlabspro_credits']; + } else { + $data['flp_credits'] = ''; + } + + return $this->load->view('extension/fraud/fraudlabspro_info', $data); + } + } + + private function fix_case($s) { + $s = ucwords(strtolower($s)); + $s = preg_replace_callback("/( [ a-zA-Z]{1}')([a-zA-Z0-9]{1})/s", create_function('$matches', 'return $matches[1].strtoupper($matches[2]);'), $s); + return $s; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/fraud/ip.php b/public/admin/controller/extension/fraud/ip.php new file mode 100644 index 0000000..fec9b53 --- /dev/null +++ b/public/admin/controller/extension/fraud/ip.php @@ -0,0 +1,171 @@ +<?php +class ControllerExtensionFraudIp extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/ip'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_ip', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/ip', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/ip', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_ip_order_status_id'])) { + $data['fraud_ip_order_status_id'] = $this->request->post['fraud_ip_order_status_id']; + } else { + $data['fraud_ip_order_status_id'] = $this->config->get('fraud_ip_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_ip_status'])) { + $data['fraud_ip_status'] = $this->request->post['fraud_ip_status']; + } else { + $data['fraud_ip_status'] = $this->config->get('fraud_ip_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/ip', $data)); + } + + public function install() { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function ip() { + $this->load->language('extension/fraud/ip'); + + $this->load->model('extension/fraud/ip'); + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['ips'] = array(); + + $results = $this->model_extension_fraud_ip->getIps(($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['ips'][] = array( + 'ip' => $result['ip'], + 'total' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']), + 'date_added' => date('d/m/y', strtotime($result['date_added'])), + 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'], true) + ); + } + + $ip_total = $this->model_extension_fraud_ip->getTotalIps(); + + $pagination = new Pagination(); + $pagination->total = $ip_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('extension/fraud/ip/ip', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($ip_total - 10)) ? $ip_total : ((($page - 1) * 10) + 10), $ip_total, ceil($ip_total / 10)); + + $this->response->setOutput($this->load->view('extension/fraud/ip_ip', $data)); + } + + public function addIp() { + $this->load->language('extension/fraud/ip'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/fraud/ip'); + + if (!$this->model_extension_fraud_ip->getTotalIpsByIp($this->request->post['ip'])) { + $this->model_extension_fraud_ip->addIp($this->request->post['ip']); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeIp() { + $this->load->language('extension/fraud/ip'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->removeIp($this->request->post['ip']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/fraud/maxmind.php b/public/admin/controller/extension/fraud/maxmind.php new file mode 100644 index 0000000..ffa17dc --- /dev/null +++ b/public/admin/controller/extension/fraud/maxmind.php @@ -0,0 +1,429 @@ +<?php +class ControllerExtensionFraudMaxMind extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/maxmind'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_maxmind', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/maxmind', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/maxmind', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_maxmind_key'])) { + $data['fraud_maxmind_key'] = $this->request->post['fraud_maxmind_key']; + } else { + $data['fraud_maxmind_key'] = $this->config->get('fraud_maxmind_key'); + } + + if (isset($this->request->post['fraud_maxmind_score'])) { + $data['fraud_maxmind_score'] = $this->request->post['fraud_maxmind_score']; + } else { + $data['fraud_maxmind_score'] = $this->config->get('fraud_maxmind_score'); + } + + if (isset($this->request->post['fraud_maxmind_order_status_id'])) { + $data['fraud_maxmind_order_status_id'] = $this->request->post['fraud_maxmind_order_status_id']; + } else { + $data['fraud_maxmind_order_status_id'] = $this->config->get('fraud_maxmind_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_maxmind_status'])) { + $data['fraud_maxmind_status'] = $this->request->post['fraud_maxmind_status']; + } else { + $data['fraud_maxmind_status'] = $this->config->get('fraud_maxmind_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/maxmind', $data)); + } + + public function install() { + $this->load->model('extension/fraud/maxmind'); + + $this->model_extension_fraud_maxmind->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/maxmind'); + + $this->model_extension_fraud_maxmind->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/maxmind')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['fraud_maxmind_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + public function order() { + $this->load->language('extension/fraud/maxmind'); + + $this->load->model('extension/fraud/maxmind'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $fraud_info = $this->model_extension_fraud_maxmind->getOrder($order_id); + + if ($fraud_info) { + $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['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']; + + return $this->load->view('extension/fraud/maxmind_info', $data); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/account.php b/public/admin/controller/extension/module/account.php new file mode 100644 index 0000000..c424934 --- /dev/null +++ b/public/admin/controller/extension/module/account.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleAccount extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/account'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_account', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/account', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/account', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_account_status'])) { + $data['module_account_status'] = $this->request->post['module_account_status']; + } else { + $data['module_account_status'] = $this->config->get('module_account_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/account', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/account')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/amazon_login.php b/public/admin/controller/extension/module/amazon_login.php new file mode 100644 index 0000000..0247dfb --- /dev/null +++ b/public/admin/controller/extension/module/amazon_login.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionModuleAmazonLogin extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + + $this->load->language('extension/module/amazon_login'); + + $this->load->model('setting/setting'); + $this->load->model('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_amazon_login', $this->request->post); + + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + $this->model_setting_event->addEvent('amazon_login', 'catalog/controller/account/logout/after', 'extension/module/amazon_login/logout'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/amazon_login', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/amazon_login', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['module_amazon_login_button_type'])) { + $data['module_amazon_login_button_type'] = $this->request->post['module_amazon_login_button_type']; + } elseif ($this->config->get('module_amazon_login_button_type')) { + $data['module_amazon_login_button_type'] = $this->config->get('module_amazon_login_button_type'); + } else { + $data['module_amazon_login_button_type'] = 'LwA'; + } + + if (isset($this->request->post['module_amazon_login_button_colour'])) { + $data['module_amazon_login_button_colour'] = $this->request->post['module_amazon_login_button_colour']; + } elseif ($this->config->get('module_amazon_login_button_colour')) { + $data['module_amazon_login_button_colour'] = $this->config->get('module_amazon_login_button_colour'); + } else { + $data['module_amazon_login_button_colour'] = 'gold'; + } + + if (isset($this->request->post['module_amazon_login_button_size'])) { + $data['module_amazon_login_button_size'] = $this->request->post['module_amazon_login_button_size']; + } elseif ($this->config->get('module_amazon_login_button_size')) { + $data['module_amazon_login_button_size'] = $this->config->get('module_amazon_login_button_size'); + } else { + $data['module_amazon_login_button_size'] = 'medium'; + } + + if (isset($this->request->post['module_amazon_login_status'])) { + $data['module_amazon_login_status'] = $this->request->post['module_amazon_login_status']; + } else { + $data['module_amazon_login_status'] = $this->config->get('module_amazon_login_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/amazon_login', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/amazon_login')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + $this->model_setting_event->addEvent('amazon_login', 'catalog/controller/account/logout/after', 'extension/module/amazon_login/logout'); + } + + public function uninstall() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + } + +} diff --git a/public/admin/controller/extension/module/amazon_pay.php b/public/admin/controller/extension/module/amazon_pay.php new file mode 100644 index 0000000..441eabf --- /dev/null +++ b/public/admin/controller/extension/module/amazon_pay.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionModuleAmazonPay extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + $this->load->language('extension/module/amazon_pay'); + + $this->load->model('setting/setting'); + $this->load->model('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_amazon_pay', $this->request->post); + + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + $this->model_setting_event->addEvent('amazon_pay', 'catalog/controller/account/logout/after', 'extension/module/amazon_pay/logout'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'separator' => false + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true), + 'separator' => ' :: ' + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/amazon_pay', 'user_token=' . $this->session->data['user_token'], true), + 'separator' => ' :: ' + ); + + $data['action'] = $this->url->link('extension/module/amazon_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['module_amazon_pay_button_type'])) { + $data['module_amazon_pay_button_type'] = $this->request->post['module_amazon_pay_button_type']; + } elseif ($this->config->get('module_amazon_pay_button_type')) { + $data['module_amazon_pay_button_type'] = $this->config->get('module_amazon_pay_button_type'); + } else { + $data['module_amazon_pay_button_type'] = 'PwA'; + } + + if (isset($this->request->post['module_amazon_pay_button_colour'])) { + $data['module_amazon_pay_button_colour'] = $this->request->post['module_amazon_pay_button_colour']; + } elseif ($this->config->get('module_amazon_pay_button_colour')) { + $data['module_amazon_pay_button_colour'] = $this->config->get('module_amazon_pay_button_colour'); + } else { + $data['module_amazon_pay_button_colour'] = 'gold'; + } + + if (isset($this->request->post['module_amazon_pay_button_size'])) { + $data['module_amazon_pay_button_size'] = $this->request->post['module_amazon_pay_button_size']; + } elseif ($this->config->get('module_amazon_pay_button_size')) { + $data['module_amazon_pay_button_size'] = $this->config->get('module_amazon_pay_button_size'); + } else { + $data['module_amazon_pay_button_size'] = 'medium'; + } + + if (isset($this->request->post['module_amazon_pay_status'])) { + $data['module_amazon_pay_status'] = $this->request->post['module_amazon_pay_status']; + } else { + $data['module_amazon_pay_status'] = $this->config->get('module_amazon_pay_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/amazon_pay', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/amazon_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + } + + public function uninstall() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + } + +} diff --git a/public/admin/controller/extension/module/banner.php b/public/admin/controller/extension/module/banner.php new file mode 100644 index 0000000..a2e47e9 --- /dev/null +++ b/public/admin/controller/extension/module/banner.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionModuleBanner extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('banner', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = ''; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/banner', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/bestseller.php b/public/admin/controller/extension/module/bestseller.php new file mode 100644 index 0000000..3b5db39 --- /dev/null +++ b/public/admin/controller/extension/module/bestseller.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleBestSeller extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/bestseller'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('bestseller', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/bestseller', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/bestseller')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/carousel.php b/public/admin/controller/extension/module/carousel.php new file mode 100644 index 0000000..0d0c244 --- /dev/null +++ b/public/admin/controller/extension/module/carousel.php @@ -0,0 +1,158 @@ +<?php +class ControllerExtensionModuleCarousel extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/carousel'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('carousel', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 130; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 100; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/carousel', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/carousel')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/category.php b/public/admin/controller/extension/module/category.php new file mode 100644 index 0000000..1eb9fe0 --- /dev/null +++ b/public/admin/controller/extension/module/category.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleCategory extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_category', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/category', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/category', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_category_status'])) { + $data['module_category_status'] = $this->request->post['module_category_status']; + } else { + $data['module_category_status'] = $this->config->get('module_category_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/category', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/category')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/divido_calculator.php b/public/admin/controller/extension/module/divido_calculator.php new file mode 100644 index 0000000..9442142 --- /dev/null +++ b/public/admin/controller/extension/module/divido_calculator.php @@ -0,0 +1,64 @@ +<?php +class ControllerExtensionModuleDividoCalculator extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/divido_calculator'); + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_divido_calculator', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/divido_calculator', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/divido_calculator', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_divido_calculator_status'])) { + $data['module_divido_calculator_status'] = $this->request->post['module_divido_calculator_status']; + } else { + $data['module_divido_calculator_status'] = $this->config->get('module_divido_calculator_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/divido_calculator', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/divido_calculator')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/ebay_listing.php b/public/admin/controller/extension/module/ebay_listing.php new file mode 100644 index 0000000..2446110 --- /dev/null +++ b/public/admin/controller/extension/module/ebay_listing.php @@ -0,0 +1,208 @@ +<?php +class ControllerExtensionModuleEbayListing extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/ebay_listing'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_ebay_listing', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->cache->delete('ebay'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/ebay_listing', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/ebay_listing', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['ebay_listing_username'])) { + $data['ebay_listing_username'] = $this->request->post['ebay_listing_username']; + } else { + $data['ebay_listing_username'] = $this->config->get('ebay_listing_username'); + } + + if (isset($this->request->post['ebay_listing_keywords'])) { + $data['ebay_listing_keywords'] = $this->request->post['ebay_listing_keywords']; + } else { + $data['ebay_listing_keywords'] = $this->config->get('ebay_listing_keywords'); + } + + if (isset($this->request->post['ebay_listing_description'])) { + $data['ebay_listing_description'] = $this->request->post['ebay_listing_description']; + } else { + $data['ebay_listing_description'] = $this->config->get('ebay_listing_description'); + } + + if (isset($this->request->post['ebay_listing_limit'])) { + $data['ebay_listing_limit'] = $this->request->post['ebay_listing_limit']; + } elseif ($this->config->has('ebay_listing_limit')) { + $data['ebay_listing_limit'] = $this->config->get('ebay_listing_limit'); + } else { + $data['ebay_listing_limit'] = 5; + } + + if (isset($this->request->post['ebay_listing_width'])) { + $data['ebay_listing_width'] = $this->request->post['width']; + } elseif ($this->config->has('ebay_listing_width')) { + $data['ebay_listing_width'] = $this->config->get('ebay_listing_width'); + } else { + $data['ebay_listing_width'] = 200; + } + + if (isset($this->request->post['ebay_listing_height'])) { + $data['ebay_listing_height'] = $this->request->post['ebay_listing_height']; + } elseif ($this->config->has('ebay_listing_height')) { + $data['ebay_listing_height'] = $this->config->get('ebay_listing_height'); + } else { + $data['ebay_listing_height'] = 200; + } + + if (isset($this->request->post['ebay_listing_sort'])) { + $data['ebay_listing_sort'] = $this->request->post['ebay_listing_sort']; + } elseif ($this->config->has('ebay_listing_sort')) { + $data['ebay_listing_sort'] = $this->config->get('ebay_listing_sort'); + } else { + $data['ebay_listing_sort'] = 'StartTimeNewest'; + } + + if (isset($this->request->post['ebay_listing_site'])) { + $data['ebay_listing_site'] = $this->request->post['ebay_listing_site']; + } else { + $data['ebay_listing_site'] = $this->config->get('ebay_listing_site'); + } + + $data['sites'] = array(); + + $data['sites'][] = array( + 'text' => 'USA', + 'value' => 0 + ); + + $data['sites'][] = array( + 'text' => 'UK', + 'value' => 3 + ); + $data['sites'][] = array( + 'text' => 'Australia', + 'value' => 15 + ); + + $data['sites'][] = array( + 'text' => 'Canada (English)', + 'value' => 2 + ); + + $data['sites'][] = array( + 'text' => 'France', + 'value' => 71 + ); + $data['sites'][] = array( + 'text' => 'Germany', + 'value' => 77 + ); + $data['sites'][] = array( + 'text' => 'Italy', + 'value' => 101 + ); + $data['sites'][] = array( + 'text' => 'Spain', + 'value' => 186 + ); + $data['sites'][] = array( + 'text' => 'Ireland', + 'value' => 205 + ); + + $data['sites'][] = array( + 'text' => 'Austria', + 'value' => 16 + ); + + $data['sites'][] = array( + 'text' => 'Netherlands', + 'value' => 146 + ); + + $data['sites'][] = array( + 'text' => 'Belgium (French)', + 'value' => 23 + ); + + $data['sites'][] = array( + 'text' => 'Belgium (Dutch)', + 'value' => 123 + ); + + if (isset($this->request->post['ebay_listing_status'])) { + $data['ebay_listing_status'] = $this->request->post['ebay_listing_status']; + } else { + $data['ebay_listing_status'] = $this->config->get('ebay_listing_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/ebay_listing', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/ebay_listing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['ebay_listing_width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['ebay_listing_height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/featured.php b/public/admin/controller/extension/module/featured.php new file mode 100644 index 0000000..d72d54e --- /dev/null +++ b/public/admin/controller/extension/module/featured.php @@ -0,0 +1,175 @@ +<?php +class ControllerExtensionModuleFeatured extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/featured'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('featured', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + $this->load->model('catalog/product'); + + $data['products'] = array(); + + if (!empty($this->request->post['product'])) { + $products = $this->request->post['product']; + } elseif (!empty($module_info['product'])) { + $products = $module_info['product']; + } else { + $products = array(); + } + + foreach ($products as $product_id) { + $product_info = $this->model_catalog_product->getProduct($product_id); + + if ($product_info) { + $data['products'][] = array( + 'product_id' => $product_info['product_id'], + 'name' => $product_info['name'] + ); + } + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/featured', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/featured')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/filter.php b/public/admin/controller/extension/module/filter.php new file mode 100644 index 0000000..0b0170a --- /dev/null +++ b/public/admin/controller/extension/module/filter.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModulefilter extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_filter', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/filter', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/filter', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_filter_status'])) { + $data['module_filter_status'] = $this->request->post['module_filter_status']; + } else { + $data['module_filter_status'] = $this->config->get('module_filter_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/filter', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/filter')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/google_hangouts.php b/public/admin/controller/extension/module/google_hangouts.php new file mode 100644 index 0000000..8f6058f --- /dev/null +++ b/public/admin/controller/extension/module/google_hangouts.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionModuleGoogleHangouts extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/google_hangouts'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_google_hangouts', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/google_hangouts', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/google_hangouts', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_google_hangouts_code'])) { + $data['module_google_hangouts_code'] = $this->request->post['module_google_hangouts_code']; + } else { + $data['module_google_hangouts_code'] = $this->config->get('module_google_hangouts_code'); + } + + if (isset($this->request->post['module_google_hangouts_status'])) { + $data['module_google_hangouts_status'] = $this->request->post['module_google_hangouts_status']; + } else { + $data['module_google_hangouts_status'] = $this->config->get('module_google_hangouts_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/google_hangouts', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/google_hangouts')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['module_google_hangouts_code']) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/html.php b/public/admin/controller/extension/module/html.php new file mode 100644 index 0000000..f34cace --- /dev/null +++ b/public/admin/controller/extension/module/html.php @@ -0,0 +1,118 @@ +<?php +class ControllerExtensionModuleHTML extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/html'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('html', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['module_description'])) { + $data['module_description'] = $this->request->post['module_description']; + } elseif (!empty($module_info)) { + $data['module_description'] = $module_info['module_description']; + } else { + $data['module_description'] = array(); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/html', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/html')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/information.php b/public/admin/controller/extension/module/information.php new file mode 100644 index 0000000..107aa3f --- /dev/null +++ b/public/admin/controller/extension/module/information.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleInformation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_information', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/information', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/information', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_information_status'])) { + $data['module_information_status'] = $this->request->post['module_information_status']; + } else { + $data['module_information_status'] = $this->config->get('module_information_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/information', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/information')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/klarna_checkout_module.php b/public/admin/controller/extension/module/klarna_checkout_module.php new file mode 100644 index 0000000..9d0b200 --- /dev/null +++ b/public/admin/controller/extension/module/klarna_checkout_module.php @@ -0,0 +1,72 @@ +<?php +class ControllerExtensionModuleKlarnaCheckoutModule extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/klarna_checkout_module'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_klarna_checkout_module', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/klarna_checkout_module', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/klarna_checkout_module', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_klarna_checkout_status'])) { + $data['module_klarna_checkout_status'] = $this->request->post['module_klarna_checkout_status']; + } else { + $data['module_klarna_checkout_status'] = $this->config->get('module_klarna_checkout_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/klarna_checkout_module', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/klarna_checkout_module')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->error) { + return true; + } else { + return false; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/latest.php b/public/admin/controller/extension/module/latest.php new file mode 100644 index 0000000..f01f34e --- /dev/null +++ b/public/admin/controller/extension/module/latest.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleLatest extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/latest'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('latest', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/latest', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/latest')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/laybuy_layout.php b/public/admin/controller/extension/module/laybuy_layout.php new file mode 100644 index 0000000..bb34b4e --- /dev/null +++ b/public/admin/controller/extension/module/laybuy_layout.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleLaybuyLayout extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->language('extension/module/laybuy_layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_laybuy_layout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/laybuy_layout', 'user_token=' . $this->session->data['user_token'], true) + ); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['action'] = $this->url->link('extension/module/laybuy_layout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_laybuy_layout_status'])) { + $data['module_laybuy_layout_status'] = $this->request->post['module_laybuy_layout_status']; + } else { + $data['module_laybuy_layout_status'] = $this->config->get('module_laybuy_layout_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/laybuy_layout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/laybuy_layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/pilibaba_button.php b/public/admin/controller/extension/module/pilibaba_button.php new file mode 100644 index 0000000..1948588 --- /dev/null +++ b/public/admin/controller/extension/module/pilibaba_button.php @@ -0,0 +1,65 @@ +<?php +class ControllerExtensionModulePilibabaButton extends Controller { + public function index() { + $this->load->language('extension/module/pilibaba_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pilibaba_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pilibaba_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pilibaba_button', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_pilibaba_button_status'])) { + $data['module_pilibaba_button_status'] = $this->request->post['module_pilibaba_button_status']; + } else { + $data['module_pilibaba_button_status'] = $this->config->get('module_pilibaba_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pilibaba_button', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pilibaba_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/pp_braintree_button.php b/public/admin/controller/extension/module/pp_braintree_button.php new file mode 100644 index 0000000..bce800a --- /dev/null +++ b/public/admin/controller/extension/module/pp_braintree_button.php @@ -0,0 +1,93 @@ +<?php +class ControllerExtensionModulePPBraintreeButton extends Controller { + public function index() { + $this->load->language('extension/module/pp_braintree_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_braintree_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_braintree_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_braintree_button', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + $data['layouts'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['module_pp_braintree_button_status'])) { + $data['module_pp_braintree_button_status'] = $this->request->post['module_pp_braintree_button_status']; + } else { + $data['module_pp_braintree_button_status'] = $this->config->get('module_pp_braintree_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_braintree_button', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $settings['module_pp_braintree_button_status'] = 1; + + $this->model_setting_setting->editSetting('module_pp_braintree_button', $settings); + } + + public function configure() { + $this->load->language('extension/extension/module'); + + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_setting_extension->install('module', 'pp_braintree_button'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/pp_braintree_button'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/pp_braintree_button'); + + $this->install(); + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_braintree_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/pp_button.php b/public/admin/controller/extension/module/pp_button.php new file mode 100644 index 0000000..5ca281d --- /dev/null +++ b/public/admin/controller/extension/module/pp_button.php @@ -0,0 +1,94 @@ +<?php +class ControllerExtensionModulePPButton extends Controller { + public function index() { + $this->load->language('extension/module/pp_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_button', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['layouts'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['module_pp_button_status'])) { + $data['module_pp_button_status'] = $this->request->post['module_pp_button_status']; + } else { + $data['module_pp_button_status'] = $this->config->get('module_pp_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_button', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $settings['module_pp_button_status'] = 1; + + $this->model_setting_setting->editSetting('module_pp_button', $settings); + } + + public function configure() { + $this->load->language('extension/extension/module'); + + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_setting_extension->install('module', 'pp_button'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/pp_button'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/pp_button'); + + $this->install(); + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/pp_login.php b/public/admin/controller/extension/module/pp_login.php new file mode 100644 index 0000000..c174cd6 --- /dev/null +++ b/public/admin/controller/extension/module/pp_login.php @@ -0,0 +1,295 @@ +<?php +class ControllerExtensionModulePPLogin extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/pp_login'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_login', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['client_id'])) { + $data['error_client_id'] = $this->error['client_id']; + } else { + $data['error_client_id'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_login', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_login', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_pp_login_client_id'])) { + $data['module_pp_login_client_id'] = $this->request->post['module_pp_login_client_id']; + } else { + $data['module_pp_login_client_id'] = $this->config->get('module_pp_login_client_id'); + } + + if (isset($this->request->post['module_pp_login_secret'])) { + $data['module_pp_login_secret'] = $this->request->post['module_pp_login_secret']; + } else { + $data['module_pp_login_secret'] = $this->config->get('module_pp_login_secret'); + } + + if (isset($this->request->post['module_pp_login_sandbox'])) { + $data['module_pp_login_sandbox'] = $this->request->post['module_pp_login_sandbox']; + } else { + $data['module_pp_login_sandbox'] = $this->config->get('module_pp_login_sandbox'); + } + + if (isset($this->request->post['module_pp_login_debug'])) { + $data['module_pp_login_debug'] = $this->request->post['module_pp_login_debug']; + } else { + $data['module_pp_login_debug'] = $this->config->get('module_pp_login_debug'); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['module_pp_login_customer_group_id'])) { + $data['module_pp_login_customer_group_id'] = $this->request->post['module_pp_login_customer_group_id']; + } else { + $data['module_pp_login_customer_group_id'] = $this->config->get('module_pp_login_customer_group_id'); + } + + if (isset($this->request->post['module_pp_login_button_colour'])) { + $data['module_pp_login_button_colour'] = $this->request->post['module_pp_login_button_colour']; + } elseif ($this->config->get('module_pp_login_button_colour')) { + $data['module_pp_login_button_colour'] = $this->config->get('module_pp_login_button_colour'); + } else { + $data['module_pp_login_button_colour'] = 'blue'; + } + + if (isset($this->request->post['module_pp_login_seamless'])) { + $data['module_pp_login_seamless'] = $this->request->post['module_pp_login_seamless']; + } else { + $data['module_pp_login_seamless'] = $this->config->get('module_pp_login_seamless'); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $data['locales'] = array(); + + $data['locales'][] = array( + 'value' => 'en-gb', + 'text' => 'English (Great Britain)' + ); + + $data['locales'][] = array( + 'value' => 'zh-cn', + 'text' => 'Chinese (People\'s Republic of China)' + ); + + $data['locales'][] = array( + 'value' => 'zh-hk', + 'text' => 'Chinese (Hong Kong)', + ); + + $data['locales'][] = array( + 'value' => 'zh-tw', + 'text' => 'Chinese (Taiwan)' + ); + + $data['locales'][] = array( + 'value' => 'zh-xc', + 'text' => 'Chinese (US)' + ); + + $data['locales'][] = array( + 'value' => 'da-dk', + 'text' => 'Danish' + ); + + $data['locales'][] = array( + 'value' => 'nl-nl', + 'text' => 'Dutch' + ); + + $data['locales'][] = array( + 'value' => 'en-au', + 'text' => 'English (Australia)' + ); + + $data['locales'][] = array( + 'value' => 'en-us', + 'text' => 'English (US)', + ); + + $data['locales'][] = array( + 'value' => 'fr-fr', + 'text' => 'French' + ); + + $data['locales'][] = array( + 'value' => 'fr-ca', + 'text' => 'French (Canada)' + ); + + $data['locales'][] = array( + 'value' => 'fr-xc', + 'text' => 'French (international)' + ); + + $data['locales'][] = array( + 'value' => 'de-de', + 'text' => 'German' + ); + + $data['locales'][] = array( + 'value' => 'he-il', + 'text' => 'Hebrew (Israel)' + ); + + $data['locales'][] = array( + 'value' => 'id-id', + 'text' => 'Indonesian' + ); + + $data['locales'][] = array( + 'value' => 'it-il', + 'text' => 'Italian' + ); + + $data['locales'][] = array( + 'value' => 'ja-jp' , + 'text' => 'Japanese' + ); + + $data['locales'][] = array( + 'value' => 'no-no', + 'text' => 'Norwegian' + ); + + $data['locales'][] = array( + 'value' => 'pl-pl', + 'text' => 'Polish'); + + $data['locales'][] = array( + 'value' => 'pt-pt', + 'text' => 'Portuguese' + ); + + $data['locales'][] = array( + 'value' => 'pt-br', + 'text' => 'Portuguese (Brazil)' + ); + + $data['locales'][] = array( + 'value' => 'ru-ru', + 'text' => 'Russian' + ); + + $data['locales'][] = array( + 'value' => 'es-es', + 'text' => 'Spanish' + ); + + $data['locales'][] = array( + 'value' => 'es-xc', + 'text' => 'Spanish (Mexico)' + ); + + $data['locales'][] = array( + 'value' => 'sv-se', + 'text' => 'Swedish' + ); + + $data['locales'][] = array( + 'value' => 'th-th', + 'text' => 'Thai' + ); + + $data['locales'][] = array( + 'value' => 'tr-tr', + 'text' => 'Turkish' + ); + + if (isset($this->request->post['module_pp_login_locale'])) { + $data['module_pp_login_locale'] = $this->request->post['module_pp_login_locale']; + } else { + $data['module_pp_login_locale'] = $this->config->get('module_pp_login_locale'); + } + + $data['return_url'] = HTTPS_CATALOG . 'index.php?route=extension/module/pp_login/login'; + + if (isset($this->request->post['module_pp_login_status'])) { + $data['module_pp_login_status'] = $this->request->post['module_pp_login_status']; + } else { + $data['module_pp_login_status'] = $this->config->get('module_pp_login_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_login', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_login')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['module_pp_login_client_id']) { + $this->error['client_id'] = $this->language->get('error_client_id'); + } + + if (!$this->request->post['module_pp_login_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('marketplace/event'); + + $this->model_setting_event->addEvent('pp_login', 'catalog/controller/account/logout/after', 'extension/module/pp_login/logout'); + } + + public function uninstall() { + $this->load->model('marketplace/event'); + + $this->model_setting_event->deleteEventByCode('pp_login'); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/sagepay_direct_cards.php b/public/admin/controller/extension/module/sagepay_direct_cards.php new file mode 100644 index 0000000..ae5b188 --- /dev/null +++ b/public/admin/controller/extension/module/sagepay_direct_cards.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleSagepayDirectCards extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/sagepay_direct_cards'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_sagepay_direct_cards', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/sagepay_direct_cards', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/sagepay_direct_cards', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_sagepay_direct_cards_status'])) { + $data['module_sagepay_direct_cards_status'] = $this->request->post['module_sagepay_direct_cards_status']; + } else { + $data['module_sagepay_direct_cards_status'] = $this->config->get('module_sagepay_direct_cards_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/sagepay_direct_cards', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/sagepay_direct_cards')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/sagepay_server_cards.php b/public/admin/controller/extension/module/sagepay_server_cards.php new file mode 100644 index 0000000..1b8a480 --- /dev/null +++ b/public/admin/controller/extension/module/sagepay_server_cards.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleSagepayServerCards extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/sagepay_server_cards'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_sagepay_server_cards', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/sagepay_server_cards', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/sagepay_server_cards', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_sagepay_server_cards_status'])) { + $data['module_sagepay_server_cards_status'] = $this->request->post['module_sagepay_server_cards_status']; + } else { + $data['module_sagepay_server_cards_status'] = $this->config->get('module_sagepay_server_cards_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/sagepay_server_cards', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/sagepay_server_cards')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/slideshow.php b/public/admin/controller/extension/module/slideshow.php new file mode 100644 index 0000000..dc31c00 --- /dev/null +++ b/public/admin/controller/extension/module/slideshow.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionModuleSlideshow extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/slideshow'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('slideshow', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = ''; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/slideshow', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/slideshow')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/special.php b/public/admin/controller/extension/module/special.php new file mode 100644 index 0000000..ef86dd3 --- /dev/null +++ b/public/admin/controller/extension/module/special.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleSpecial extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/special'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('special', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/special', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/special')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/store.php b/public/admin/controller/extension/module/store.php new file mode 100644 index 0000000..cad1dd9 --- /dev/null +++ b/public/admin/controller/extension/module/store.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionModuleStore extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_store', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/store', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/store', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_store_admin'])) { + $data['module_store_admin'] = $this->request->post['module_store_admin']; + } else { + $data['module_store_admin'] = $this->config->get('module_store_admin'); + } + + if (isset($this->request->post['module_store_status'])) { + $data['module_store_status'] = $this->request->post['module_store_status']; + } else { + $data['module_store_status'] = $this->config->get('module_store_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/store', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/store')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/amazon.php b/public/admin/controller/extension/openbay/amazon.php new file mode 100644 index 0000000..dd3178b --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon.php @@ -0,0 +1,1129 @@ +<?php +class ControllerExtensionOpenbayAmazon extends Controller { + public function install() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazon_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazon_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazon_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazon_product'); + + $this->model_extension_openbay_amazon->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_amazon->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazon'); + + $this->load->language('extension/openbay/amazon'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + $data['success'] = ''; + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->amazon->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/amazon/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_subscription'] = $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['link_item_link'] = $this->url->link('extension/openbay/amazon/itemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['link_stock_updates'] = $this->url->link('extension/openbay/amazon/stockUpdates', 'user_token=' . $this->session->data['user_token'], true); + $data['link_saved_listings'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_listing'] = $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_linking'] = $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=amazon'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon', $data)); + } + + public function stockUpdates() { + $this->load->language('extension/openbay/amazon_stockupdates'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/stockUpdates', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $request_arg = array(); + + if (isset($this->request->get['filter_date_start'])) { + $request_arg['date_start'] = date("Y-m-d", strtotime($this->request->get['filter_date_start'])); + } else { + $request_arg['date_start'] = date("Y-m-d"); + } + + if (isset($this->request->get['filter_date_end'])) { + $request_arg['date_end'] = date("Y-m-d", strtotime($this->request->get['filter_date_end'])); + } else { + $request_arg['date_end'] = date("Y-m-d"); + } + + $data['date_start'] = $request_arg['date_start']; + $data['date_end'] = $request_arg['date_end']; + + $xml = $this->openbay->amazon->getStockUpdatesStatus($request_arg); + $xml_object = simplexml_load_string($xml); + + $data['table_data'] = array(); + + if ($xml_object !== false) { + $table_data = array(); + + foreach($xml_object->update as $update_node) { + $row = array( + 'date_requested' => (string)$update_node->date_requested, + 'date_updated' => (string)$update_node->date_updated, + 'status' => (string)$update_node->status, + ); + + $data_items = array(); + + foreach($update_node->data->product as $product_node) { + $data_items[] = array( + 'sku' => (string)$product_node->sku, + 'stock' => (int)$product_node->stock + ); + } + + $row['data'] = $data_items; + $table_data[(int)$update_node->ref] = $row; + } + + $data['table_data'] = $table_data; + } else { + $data['error'] = $data['error_api_connection']; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_stock_updates', $data)); + + } + + public function subscription() { + $this->load->language('extension/openbay/amazon_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $response = simplexml_load_string($this->openbay->amazon->call('plans/getPlans')); + + $data['plans'] = array(); + + if ($response) { + foreach ($response->Plan as $plan) { + $data['plans'][] = array( + 'title' => (string)$plan->Title, + 'description' => (string)$plan->Description, + 'order_frequency' => (string)$plan->OrderFrequency, + 'product_listings' => (string)$plan->ProductListings, + 'bulk_listing' => (string)$plan->BulkListing, + 'price' => (string)$plan->Price, + ); + } + } + + $response = simplexml_load_string($this->openbay->amazon->call('plans/getUsersPlans')); + + $plan = false; + + if ($response) { + $plan = array( + 'merchant_id' => (string)$response->MerchantId, + 'user_status' => (string)$response->UserStatus, + 'title' => (string)$response->Title, + 'description' => (string)$response->Description, + 'price' => (string)$response->Price, + 'order_frequency' => (string)$response->OrderFrequency, + 'product_listings' => (string)$response->ProductListings, + 'listings_remain' => (string)$response->ListingsRemain, + 'listings_reserved' => (string)$response->ListingsReserved, + 'bulk_listing' => (string)$response->BulkListing, + ); + } + + $data['user_plan'] = $plan; + $data['link_change_plan'] = $this->openbay->amazon->getServer() . 'account/changePlan/?token=' . $this->config->get('openbay_amazon_token'); + $data['link_change_seller'] = $this->openbay->amazon->getServer() . 'account/changeSellerId/?token=' . $this->config->get('openbay_amazon_token'); + $data['link_register'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=subscription&utm_campaign=amazon'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_subscription', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/amazon_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazon'); + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->post['openbay_amazon_orders_marketplace_ids'])) { + $this->request->post['openbay_amazon_orders_marketplace_ids'] = array(); + } + + $settings = array_merge($settings, $this->request->post); + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + + $this->config->set('openbay_amazon_token', $this->request->post['openbay_amazon_token']); + $this->config->set('openbay_amazon_encryption_key', $this->request->post['openbay_amazon_encryption_key']); + $this->config->set('openbay_amazon_encryption_iv', $this->request->post['openbay_amazon_encryption_iv']); + + $this->openbay->amazon->setEncryptionKey($this->request->post['openbay_amazon_encryption_key']); + $this->openbay->amazon->setEncryptionIv($this->request->post['openbay_amazon_encryption_iv']); + + if (!empty($this->request->post['openbay_amazon_token']) && !empty($this->request->post['openbay_amazon_encryption_key']) && !empty($this->request->post['openbay_amazon_encryption_iv'])) { + $this->model_extension_openbay_amazon->verifyConfig($settings); + } + + $this->session->data['success'] = $this->language->get('text_settings_updated'); + $this->response->redirect($this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['marketplace_ids'] = (isset($settings['openbay_amazon_orders_marketplace_ids'])) ? (array)$settings['openbay_amazon_orders_marketplace_ids'] : array(); + $data['default_listing_marketplace_ids'] = (isset($settings['openbay_amazon_default_listing_marketplace_ids'])) ? (array)$settings['openbay_amazon_default_listing_marketplace_ids'] : array(); + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_de'), 'id' => 'A1PA6795UKMFR9', 'code' => 'de'), + array('name' => $this->language->get('text_fr'), 'id' => 'A13V1IB3VIYZZH', 'code' => 'fr'), + array('name' => $this->language->get('text_it'), 'id' => 'APJ6JRA9NG5V4', 'code' => 'it'), + array('name' => $this->language->get('text_es'), 'id' => 'A1RKKUPIHCS9HS', 'code' => 'es'), + array('name' => $this->language->get('text_uk'), 'id' => 'A1F83G8C2ARO7P', 'code' => 'uk'), + ); + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['openbay_amazon_status'] = isset($settings['openbay_amazon_status']) ? $settings['openbay_amazon_status'] : ''; + $data['openbay_amazon_token'] = isset($settings['openbay_amazon_token']) ? $settings['openbay_amazon_token'] : ''; + $data['openbay_amazon_encryption_key'] = isset($settings['openbay_amazon_encryption_key']) ? $settings['openbay_amazon_encryption_key'] : ''; + $data['openbay_amazon_encryption_iv'] = isset($settings['openbay_amazon_encryption_iv']) ? $settings['openbay_amazon_encryption_iv'] : ''; + $data['openbay_amazon_listing_tax_added'] = isset($settings['openbay_amazon_listing_tax_added']) ? $settings['openbay_amazon_listing_tax_added'] : '0.00'; + $data['openbay_amazon_order_tax'] = isset($settings['openbay_amazon_order_tax']) ? $settings['openbay_amazon_order_tax'] : '00'; + $data['openbay_amazon_default_listing_marketplace'] = isset($settings['openbay_amazon_default_listing_marketplace']) ? $settings['openbay_amazon_default_listing_marketplace'] : ''; + $data['openbay_amazon_listing_default_condition'] = isset($settings['openbay_amazon_listing_default_condition']) ? $settings['openbay_amazon_listing_default_condition'] : ''; + + $data['carriers'] = $this->openbay->amazon->getCarriers(); + $data['openbay_amazon_default_carrier'] = isset($settings['openbay_amazon_default_carrier']) ? $settings['openbay_amazon_default_carrier'] : ''; + + $unshipped_status_id = isset($settings['openbay_amazon_order_status_unshipped']) ? $settings['openbay_amazon_order_status_unshipped'] : ''; + $partially_shipped_status_id = isset($settings['openbay_amazon_order_status_partially_shipped']) ? $settings['openbay_amazon_order_status_partially_shipped'] : ''; + $shipped_status_id = isset($settings['openbay_amazon_order_status_shipped']) ? $settings['openbay_amazon_order_status_shipped'] : ''; + $canceled_status_id = isset($settings['openbay_amazon_order_status_canceled']) ? $settings['openbay_amazon_order_status_canceled'] : ''; + + $amazon_order_statuses = array( + 'unshipped' => array('name' => $this->language->get('text_unshipped'), 'order_status_id' => $unshipped_status_id), + 'partially_shipped' => array('name' => $this->language->get('text_partially_shipped'), 'order_status_id' => $partially_shipped_status_id), + 'shipped' => array('name' => $this->language->get('text_shipped'), 'order_status_id' => $shipped_status_id), + 'canceled' => array('name' => $this->language->get('text_canceled'), 'order_status_id' => $canceled_status_id), + ); + + $data['openbay_amazon_order_customer_group'] = isset($settings['openbay_amazon_order_customer_group']) ? $settings['openbay_amazon_order_customer_group'] : ''; + + $data['amazon_order_statuses'] = $amazon_order_statuses; + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['subscription_url'] = $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['itemLinks_url'] = $this->url->link('extension/openbay/amazon_product/linkItems', 'user_token=' . $this->session->data['user_token'], true); + $data['openbay_amazon_notify_admin'] = isset($settings['openbay_amazon_notify_admin']) ? $settings['openbay_amazon_notify_admin'] : ''; + $data['link_signup'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=amazon'; + + $api_checked = false; + $api_status = false; + $api_auth = false; + + if (!empty($data['openbay_amazon_token']) && !empty($data['openbay_amazon_encryption_key']) && !empty($data['openbay_amazon_encryption_iv'])) { + $response = $this->openbay->amazon->call('ping/info', array('say hello')); + + $api_checked = true; + + if (!empty($response)) { + $ping_info = simplexml_load_string($response); + + if ($ping_info === false) { + /** + * The data from the API could not be extracted from the XML + */ + } else { + $api_status = ((string)$ping_info->Api_status == 'ok') ? true : false; + $api_auth = ((string)$ping_info->Auth == 'true') ? true : false; + } + } + } + + $data['api_status'] = $api_status; + $data['api_auth'] = $api_auth; + $data['api_checked'] = $api_checked; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_settings', $data)); + } + + public function itemLinks() { + $this->load->language('extension/openbay/amazon_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_item_links', $data)); + } + + public function savedListings() { + $this->load->language('extension/openbay/amazon_listingsaved'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + $this->load->model('extension/openbay/amazon'); + $saved_products = $this->model_extension_openbay_amazon->getSavedProducts(); + + $data['saved_products'] = array(); + + foreach($saved_products as $saved_product) { + $data['saved_products'][] = array( + 'product_id' => $saved_product['product_id'], + 'product_name' => $saved_product['product_name'], + 'product_model' => $saved_product['product_model'], + 'product_sku' => $saved_product['product_sku'], + 'amazon_sku' => $saved_product['amazon_sku'], + 'var' => $saved_product['var'], + 'edit_link' => $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $saved_product['product_id'] . '&sku=' . $saved_product['var'], true), + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_saved_listings', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/amazon')) { + $this->error = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + return true; + } + + return false; + } + + public function getVariants() { + $variants = array(); + + if ($this->openbay->addonLoad('openstock') && isset($this->request->get['product_id'])) { + $this->load->model('extension/module/openstock'); + $this->load->model('tool/image'); + $variants = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + } + + if (empty($variants)) { + $variants = false; + } else { + foreach ($variants as $key => $variant) { + if ($variant['sku'] == '') { + unset($variants[$key]); + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($variants)); + } + + public function addLink() { + if (isset($this->request->get['product_id']) && isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazon'); + + $amazon_sku = $this->request->get['amazon_sku']; + $product_id = $this->request->get['product_id']; + $var = isset($this->request->get['var']) ? $this->request->get['var'] : ''; + + $this->model_extension_openbay_amazon->linkProduct($amazon_sku, $product_id, $var); + + $logger = new Log('amazon_stocks.log'); + $logger->write('addItemLink() called for product id: ' . $product_id . ', amazon sku: ' . $amazon_sku . ', var: ' . $var); + + if ($var != '' && $this->openbay->addonLoad('openstock')) { + $logger->write('Using openStock'); + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $quantity_data = array(); + + foreach($option_stocks as $option_stock) { + if (isset($option_stock['sku']) && $option_stock['sku'] == $var) { + $quantity_data[$amazon_sku] = $option_stock['stock']; + break; + } + } + + if (!empty($quantity_data)) { + $logger->write('Updating quantities with data: ' . print_r($quantity_data, true)); + $this->openbay->amazon->updateQuantities($quantity_data); + } else { + $logger->write('No quantity data will be posted . '); + } + } else { + $this->openbay->amazon->putStockUpdateBulk(array($product_id)); + } + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function deleteLink() { + if (isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazon'); + + $amazon_sku = $this->request->get['amazon_sku']; + + $this->model_extension_openbay_amazon->removeProductLink($amazon_sku); + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getLinks() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + + $json = json_encode($this->model_extension_openbay_amazon->getProductLinks()); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getUnlinked() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + + $json = json_encode($this->model_extension_openbay_amazon->getUnlinkedProducts()); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function doBulkList() { + $this->load->language('amazon/listing'); + + if (empty($this->request->post['products'])) { + $json = array( + 'message' => $this->language->get('error_not_searched'), + ); + } else { + $this->load->model('extension/openbay/amazon_listing'); + + $delete_search_results = array(); + + $bulk_list_products = array(); + + foreach ($this->request->post['products'] as $product_id => $asin) { + $delete_search_results[] = $product_id; + + if (!empty($asin) && in_array($product_id, $this->request->post['product_ids'])) { + $bulk_list_products[$product_id] = $asin; + } + } + + $status = false; + + if ($bulk_list_products) { + $data = array(); + + $data['products'] = $bulk_list_products; + $data['marketplace'] = $this->request->post['marketplace']; + + if (!empty($this->request->post['start_selling'])) { + $data['start_selling'] = $this->request->post['start_selling']; + } + + if (!empty($this->request->post['condition']) && !empty($this->request->post['condition_note'])) { + $data['condition'] = $this->request->post['condition']; + $data['condition_note'] = $this->request->post['condition_note']; + } + + $status = $this->model_extension_openbay_amazon_listing->doBulkListing($data); + + if ($status) { + $message = $this->language->get('text_products_sent'); + + if ($delete_search_results) { + $this->model_extension_openbay_amazon_listing->deleteSearchResults($this->request->post['marketplace'], $delete_search_results); + } + } else { + $message = $this->language->get('error_sending_products'); + } + } else { + $message = $this->language->get('error_no_products_selected'); + } + + $json = array( + 'status' => $status, + 'message' => $message, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkSearch() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_bulk_listing'); + + $json = array(); + $search_data = array(); + + if (!empty($this->request->post['product_ids'])) { + foreach ($this->request->post['product_ids'] as $product_id) { + $product = $this->model_catalog_product->getProduct($product_id); + + if (empty($product['sku'])) { + $json[$product_id] = array( + 'error' => $this->language->get('error_product_sku') + ); + } + + $key = ''; + + $id_types = array('isbn', 'upc', 'ean', 'jan', 'sku'); + + foreach ($id_types as $id_type) { + if (!empty($product[$id_type])) { + $key = $id_type; + break; + } + } + + if (!$key) { + $json[$product_id] = array( + 'error' => $this->language->get('error_searchable_fields') + ); + } + + if (!isset($json[$product_id])) { + $search_data[$key][] = array( + 'product_id' => $product['product_id'], + 'value' => trim($product[$id_type]), + 'marketplace' => $this->request->post['marketplace'], + ); + + $json[$product_id] = array( + 'success' => $this->language->get('text_searching') + ); + } + } + } + + if ($search_data) { + $this->model_extension_openbay_amazon_listing->doBulkSearch($search_data); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bulkListProducts() { + $this->load->language('extension/openbay/amazon_bulk_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazon->call('ping/info')); + + $bulk_listing_status = false; + + if ($ping_info) { + $bulk_listing_status = ((string)$ping_info->BulkListing == 'true') ? true : false; + } + + if (!empty($this->request->get['filter_marketplace'])) { + $filter_marketplace = $this->request->get['filter_marketplace']; + } else { + $filter_marketplace = $this->config->get('openbay_amazon_default_listing_marketplace'); + } + + $data['filter_marketplace'] = $filter_marketplace; + + $data['bulk_listing_status'] = $bulk_listing_status; + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if ($bulk_listing_status) { + $data['link_search'] = $this->url->link('extension/openbay/amazon/doBulkSearch', 'user_token=' . $this->session->data['user_token'], true); + + $data['default_condition'] = $this->config->get('openbay_amazon_listing_default_condition'); + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_de'), 'code' => 'de'), + array('name' => $this->language->get('text_fr'), 'code' => 'fr'), + array('name' => $this->language->get('text_it'), 'code' => 'it'), + array('name' => $this->language->get('text_es'), 'code' => 'es'), + array('name' => $this->language->get('text_uk'), 'code' => 'uk'), + ); + + if (!empty($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $filter = array(); + + $filter['filter_marketplace'] = $filter_marketplace; + $filter['start'] = ($page - 1) * $this->config->get('config_limit_admin'); + $filter['limit'] = $this->config->get('config_limit_admin'); + + $results = $this->model_extension_openbay_amazon->getProductSearch($filter); + $product_total = $this->model_extension_openbay_amazon->getProductSearchTotal($filter); + + $data['products'] = array(); + + foreach ($results as $result) { + $product = $this->model_catalog_product->getProduct($result['product_id']); + + if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) { + $image = $this->model_tool_image->resize($product['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + if ($result['status'] == 'searching') { + $search_status = $this->language->get('text_searching'); + } else if ($result['status'] == 'finished') { + $search_status = $this->language->get('text_finished'); + } else { + $search_status = '-'; + } + + $href = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true); + + $search_results = array(); + + if ($result['data']) { + foreach ($result['data'] as $search_result) { + $link = $this->model_extension_openbay_amazon->getAsinLink($search_result['asin'], $result['marketplace']); + + $search_results[] = array( + 'title' => $search_result['title'], + 'asin' => $search_result['asin'], + 'href' => $link, + ); + } + } + + $data['products'][] = array( + 'product_id' => $product['product_id'], + 'href' => $href, + 'name' => $product['name'], + 'model' => $product['model'], + 'image' => $image, + 'matches' => $result['matches'], + 'search_status' => $search_status, + 'search_results' => $search_results, + ); + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . '&page={page}&filter_marketplace=' . $filter_marketplace, true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_bulk_listing', $data)); + } + + public function bulkLinking() { + $this->load->language('extension/openbay/amazon_bulk_linking'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazon->call('ping/info')); + + $bulk_linking_status = false; + if ($ping_info) { + $bulk_linking_status = ((string)$ping_info->BulkLinking == 'true') ? true : false; + } + + $data['bulk_linking_status'] = $bulk_linking_status; + + if (!isset($this->request->get['marketplace'])) { + $marketplace_code = 'uk'; + } else { + $marketplace_code = $this->request->get['marketplace']; + } + + $total_linked = $this->model_extension_openbay_amazon->getTotalUnlinkedItemsFromReport($marketplace_code); + + if (isset($this->request->get['linked_item_page'])) { + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 25; + } + + $data['cancel_report_link'] = ''; + + if (isset($this->request->get['cancel_report']) && $this->request->get['cancel_report'] == 1) { + $this->load->model('setting/setting'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + $settings['openbay_amazon_processing_listing_reports'] = ''; + + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + + $this->response->redirect($this->url->link('extension/openbay/amazon/bulklinking', 'marketplace=' . $marketplace_code . '&user_token=' . $this->session->data['user_token'], true)); + } else { + $data['cancel_report_link'] = $this->url->link('extension/openbay/amazon/bulklinking', 'cancel_report=1&marketplace=uk&user_token=' . $this->session->data['user_token'], true); + } + + $marketplaces = array( + 'uk' => array( + 'name' => $this->language->get('text_uk'), + 'code' => 'uk', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=uk', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=uk', true), + ), + 'de' => array( + 'name' => $this->language->get('text_de'), + 'code' => 'de', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=de', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=de', true), + ), + 'fr' => array( + 'name' => $this->language->get('text_fr'), + 'code' => 'fr', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=fr', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=fr', true), + ), + 'it' => array( + 'name' => $this->language->get('text_it'), + 'code' => 'it', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=it', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=it', true), + ), + 'es' => array( + 'name' => $this->language->get('text_es'), + 'code' => 'es', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=es', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=es', true), + ), + ); + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = $linked_item_limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}&marketplace=' . $marketplace_code, true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($linked_item_page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) > ($total_linked - $this->config->get('config_limit_admin'))) ? $total_linked : ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total_linked, ceil($total_linked / $this->config->get('config_limit_admin'))); + + $results = $this->model_extension_openbay_amazon->getUnlinkedItemsFromReport($marketplace_code, $linked_item_limit, $linked_item_page); + + $products = array(); + + foreach ($results as $result) { + $products[] = array( + 'asin' => $result['asin'], + 'href_amazon' => $this->model_extension_openbay_amazon->getAsinLink($result['asin'], $marketplace_code), + 'amazon_sku' => $result['amazon_sku'], + 'amazon_quantity' => $result['amazon_quantity'], + 'amazon_price' => $result['amazon_price'], + 'name' => $result['name'], + 'sku' => $result['sku'], + 'quantity' => $result['quantity'], + 'combination' => $result['combination'], + 'product_id' => $result['product_id'], + 'var' => $result['var'], + 'href_product' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'], true), + ); + } + + $data['unlinked_products'] = $products; + $data['marketplaces'] = $marketplaces; + $data['marketplace_code'] = $marketplace_code; + + $data['marketplaces_processing'] = array(); + if (is_array($this->config->get('openbay_amazon_processing_listing_reports'))) { + $data['marketplaces_processing'] = $this->config->get('openbay_amazon_processing_listing_reports'); + } + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_bulk_linking', $data)); + } + + public function loadListingReport() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->language('extension/openbay/amazon_bulk_linking'); + + $marketplace = $this->request->get['marketplace']; + + $this->model_extension_openbay_amazon->deleteListingReports($marketplace); + + $request_data = array( + 'marketplace' => $marketplace, + 'response_url' => HTTPS_CATALOG . 'index.php?route=extension/openbay/amazon/listingreport', + ); + + $response = $this->openbay->amazon->call('report/listing', $request_data); + $response = json_decode($response, 1); + + $json = array(); + $json['status'] = $response['status']; + + if ($json['status']) { + $json['message'] = $this->language->get('text_report_requested'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + $settings['openbay_amazon_processing_listing_reports'][] = $marketplace; + + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + } else { + $json['message'] = $this->language->get('text_report_request_failed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkLinking() { + $this->load->model('extension/openbay/amazon'); + + $links = array(); + $skus = array(); + + if (!empty($this->request->post['link'])) { + foreach ($this->request->post['link'] as $link) { + if (!empty($link['product_id'])) { + $links[] = $link; + $skus[] = $link['amazon_sku']; + } + } + } + + if (!empty($links)) { + foreach ($links as $link) { + $this->model_extension_openbay_amazon->linkProduct($link['amazon_sku'], $link['product_id'], $link['sku']); + } + + $this->model_extension_openbay_amazon->updateAmazonSkusQuantities($skus); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('ok'))); + } + + public function doFullStockSync() { + /** + * This is used if you ever need to force a complete update of your stock levels to Amazon. + * It will get ALL products in your store then lookup any linked ones before sending to the API. + * + * This call can put serious load on your server if you have a lot of products. + * It will make a lot of database queries so ensure your php memory limit is set high enough. + */ + set_time_limit(0); + + $product_array = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product`")->rows; + + $bulk_array = array(); + + foreach ($product_array as $product) { + $bulk_array[] = $product['product_id']; + } + + $this->openbay->amazon->putStockUpdateBulk($bulk_array); + } +} diff --git a/public/admin/controller/extension/openbay/amazon_listing.php b/public/admin/controller/extension/openbay/amazon_listing.php new file mode 100644 index 0000000..99f7884 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon_listing.php @@ -0,0 +1,607 @@ +<?php +class ControllerExtensionOpenbayAmazonListing extends Controller { + public function create() { + $this->load->language('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if ($this->request->post) { + $result = $this->model_extension_openbay_amazon_listing->simpleListing($this->request->post); + + if ($result['status'] === 1) { + $this->session->data['success'] = $this->language->get('text_product_sent'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $this->session->data['error'] = sprintf($this->language->get('text_product_not_sent'), $result['message']); + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->post['product_id'] . $url, true)); + } + } + + if (isset($this->request->get['product_id'])) { + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if (empty($product_info)) { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $listing_status = $this->model_extension_openbay_amazon->getProductStatus($this->request->get['product_id']); + + if ($listing_status === 'processing' || $listing_status === 'ok') { + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } else if ($listing_status === 'error_advanced' || $listing_status === 'saved' || $listing_status === 'error_few') { + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['url_search'] = $this->url->link('extension/openbay/amazon_listing/search', 'user_token=' . $this->session->data['user_token'], true); + $data['url_advanced'] = $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true); + + $data['button_search'] = $this->language->get('button_search'); + $data['button_new'] = $this->language->get('button_new'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_amazon_price'] = $this->language->get('button_amazon_price'); + $data['button_list'] = $this->language->get('button_list'); + $data['heading_title'] = $this->language->get('heading_title'); + $data['text_not_in_catalog'] = $this->language->get('text_not_in_catalog'); + $data['text_no_results'] = $this->language->get('text_no_results'); + $data['button_view_on_amazon'] = $this->language->get('button_view_on_amazon'); + $data['text_list'] = $this->language->get('text_list'); + $data['text_placeholder_search'] = $this->language->get('text_placeholder_search'); + $data['text_placeholder_condition'] = $this->language->get('text_placeholder_condition'); + $data['column_image'] = $this->language->get('column_image'); + $data['column_asin'] = $this->language->get('column_asin'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_price'] = $this->language->get('column_price'); + $data['column_action'] = $this->language->get('column_action'); + $data['entry_sku'] = $this->language->get('entry_sku'); + $data['entry_condition'] = $this->language->get('entry_condition'); + $data['entry_condition_note'] = $this->language->get('entry_condition_note'); + $data['entry_price'] = $this->language->get('entry_price'); + $data['entry_sale_price'] = $this->language->get('entry_sale_price'); + $data['entry_sale_date'] = $this->language->get('entry_sale_date'); + $data['entry_quantity'] = $this->language->get('entry_quantity'); + $data['entry_start_selling'] = $this->language->get('entry_start_selling'); + $data['entry_restock_date'] = $this->language->get('entry_restock_date'); + $data['entry_from'] = $this->language->get('entry_from'); + $data['entry_to'] = $this->language->get('entry_to'); + $data['help_restock_date'] = $this->language->get('help_restock_date'); + $data['help_sku'] = $this->language->get('help_sku'); + $data['help_sale_price'] = $this->language->get('help_sale_price'); + $data['tab_required'] = $this->language->get('tab_required'); + $data['tab_additional'] = $this->language->get('tab_additional'); + $data['error_price'] = $this->language->get('error_price'); + $data['error_sku'] = $this->language->get('error_sku'); + $data['error_stock'] = $this->language->get('error_stock'); + + $data['form_action'] = $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true); + + $data['sku'] = trim($product_info['sku']); + + if ($this->config->get('openbay_amazon_listing_tax_added')) { + $data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazon_listing_tax_added') / 100); + } else { + $data['price'] = $product_info['price']; + } + + $data['listing_errors'] = array(); + + if ($listing_status == 'error_quick') { + $data['listing_errors'] = $this->model_extension_openbay_amazon->getProductErrors($product_info['product_id'], 3); + } + + $data['price'] = number_format($data['price'], 2, '.', ''); + $data['quantity'] = $product_info['quantity']; + $data['product_id'] = $product_info['product_id']; + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['marketplaces'] = array( + 'uk' => $this->language->get('text_united_kingdom'), + 'de' => $this->language->get('text_germany'), + 'fr' => $this->language->get('text_france'), + 'it' => $this->language->get('text_italy'), + 'es' => $this->language->get('text_spain'), + ); + + $data['default_marketplace'] = $this->config->get('openbay_amazon_default_listing_marketplace'); + $data['default_condition'] = $this->config->get('openbay_amazon_listing_default_condition'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing', $data)); + } + + public function edit() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $this->load->language('extension/openbay/amazon_listing'); + + $this->document->setTitle($this->language->get('text_edit_heading')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true), + 'text' => $this->language->get('text_edit_heading'), + ); + + $status = $this->model_extension_openbay_amazon->getProductStatus($product_id); + + if ($status === false) { + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + return; + } + + $data['product_links'] = $this->model_extension_openbay_amazon->getProductLinks($product_id); + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if ($status == 'ok' || $status == 'linked') { + $data['url_create_new'] = $this->url->link('extension/openbay/amazon_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['url_delete_links'] = $this->url->link('extension/openbay/amazon_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + } + + if ($status == 'saved') { + $data['has_saved_listings'] = true; + } else { + $data['has_saved_listings'] = false; + } + + $data['url_saved_listings'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['text_edit_heading'] = $this->language->get('text_edit_heading'); + $data['text_product_links'] = $this->language->get('text_product_links'); + $data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings'); + $data['button_create_new_listing'] = $this->language->get('button_create_new_listing'); + $data['button_remove_links'] = $this->language->get('button_remove_links'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_saved_listings'] = $this->language->get('button_saved_listings'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_model'] = $this->language->get('column_model'); + $data['column_combination'] = $this->language->get('column_combination'); + $data['column_sku'] = $this->language->get('column_sku'); + $data['column_amazon_sku'] = $this->language->get('column_amazon_sku'); + $data['column_sku_variant'] = $this->language->get('column_sku_variant'); + $data['text_no_results'] = $this->language->get('text_no_results'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing_edit', $data)); + } + + public function createNew() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->deleteProduct($product_id); + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteLinks() { + $this->load->language('extension/openbay/amazon_listing'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + + $links = $this->model_extension_openbay_amazon->getProductLinks($product_id); + foreach ($links as $link) { + $this->model_extension_openbay_amazon->removeProductLink($link['amazon_sku']); + } + $this->model_extension_openbay_amazon->deleteProduct($product_id); + $this->session->data['success'] = $this->language->get('text_links_removed'); + + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + public function search() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_listing'); + + $error = ''; + + if (empty($this->request->post['search_string'])) { + $error = $this->language->get('error_text_missing'); + } + + if (empty($this->request->post['marketplace'])) { + $error = $this->language->get('error_marketplace_missing'); + } + + if ($error) { + $json = array( + 'data' => '', + 'error' => $error, + ); + } else { + $json = array( + 'data' => $this->model_extension_openbay_amazon_listing->search($this->request->post['search_string'], $this->request->post['marketplace']), + 'error' => '', + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bestPrice() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_listing'); + + $error = ''; + + if (empty($this->request->post['asin'])) { + $error = $this->language->get('error_missing_asin'); + } + + if (empty($this->request->post['marketplace'])) { + $error = $this->language->get('error_marketplace_missing'); + } + + if (empty($this->request->post['condition'])) { + $error = $this->language->get('error_condition_missing'); + } + + if ($error) { + $json = array( + 'data' => '', + 'error' => $error, + ); + } else { + $best_price = $this->model_extension_openbay_amazon_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition'], $this->request->post['marketplace']); + + if ($best_price) { + $json = array( + 'data' => $best_price, + 'error' => '', + ); + } else { + $json = array( + 'data' => '', + 'error' => $this->language->get('error_amazon_price'), + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getProductByAsin() { + $this->load->model('extension/openbay/amazon_listing'); + + $data = $this->model_extension_openbay_amazon_listing->getProductByAsin($this->request->post['asin'], $this->request->post['market']); + + $json = array( + 'title' => (string)$data['ItemAttributes']['Title'], + 'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL']) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getBrowseNodes() { + $this->load->model('extension/openbay/amazon_listing'); + + $data = array( + 'marketplaceId' => $this->request->post['marketplaceId'], + 'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''), + ); + + $response = $this->model_extension_openbay_amazon_listing->getBrowseNodes($data); + + $this->response->setOutput($response); + } +} diff --git a/public/admin/controller/extension/openbay/amazon_product.php b/public/admin/controller/extension/openbay/amazon_product.php new file mode 100644 index 0000000..8c3ba1a --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon_product.php @@ -0,0 +1,585 @@ +<?php +class ControllerExtensionOpenbayAmazonProduct extends Controller { + public function index() { + $this->load->language('catalog/product'); + $this->load->language('extension/openbay/amazon_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_title_advanced'), + ); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + die('No product id'); + } + + if (isset($this->request->get['sku'])) { + $variation = $this->request->get['sku']; + } else { + $variation = ''; + } + $data['variation'] = $variation; + $data['errors'] = array(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $data_array = $this->request->post; + + $this->model_extension_openbay_amazon->saveProduct($product_id, $data_array); + + if ($data_array['upload_after'] === 'true') { + $upload_result = $this->uploadItems(); + if ($upload_result['status'] == 'ok') { + $this->session->data['success'] = $this->language->get('text_uploaded'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $data['errors'][] = Array('message' => $upload_result['error_message']); + } + } else { + $this->session->data['success'] = $this->language->get('text_saved_local'); + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $saved_listing_data = $this->model_extension_openbay_amazon->getProduct($product_id, $variation); + if (empty($saved_listing_data)) { + $listing_saved = false; + } else { + $listing_saved = true; + } + + $errors = $this->model_extension_openbay_amazon->getProductErrors($product_id); + foreach($errors as $error) { + $error['message'] = 'Error for SKU: "' . $error['sku'] . '" - ' . $this->formatUrlsInText($error['message']); + $data['errors'][] = $error; + } + if (!empty($errors)) { + $data['has_listing_errors'] = true; + } else { + $data['has_listing_errors'] = false; + } + + $product_info = $this->model_catalog_product->getProduct($product_id); + $data['listing_name'] = $product_info['name'] . " : " . $product_info['model']; + $data['listing_sku'] = $product_info['sku']; + $data['listing_url'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + + if ($listing_saved) { + $data['edit_product_category'] = $saved_listing_data['category']; + } else { + $data['edit_product_category'] = ''; + } + + $data['amazon_categories'] = array(); + + $amazon_templates = $this->openbay->amazon->getCategoryTemplates(); + + foreach($amazon_templates as $template) { + $template = (array)$template; + $category_data = array( + 'friendly_name' => $template['friendly_name'], + 'name' => $template['name'], + 'template' => $template['xml'] + ); + $data['amazon_categories'][] = $category_data; + } + + if ($listing_saved) { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazon_product/parseTemplateAjax&edit_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazon_product/parseTemplateAjax&product_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['url_remove_errors'] = $this->url->link('extension/openbay/amazon_product/removeErrors', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['cancel_url'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['saved_listings_url'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['main_url'] = $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['user_token'] = $this->session->data['user_token']; + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if ($this->openbay->addonLoad('openstock')) { + $this->load->model('extension/module/openstock'); + $data['options'] = $this->model_setting_module_openstock->getVariants($product_id); + } else { + $data['options'] = array(); + } + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_germany'), 'id' => 'A1PA6795UKMFR9', 'code' => 'de'), + array('name' => $this->language->get('text_france'), 'id' => 'A13V1IB3VIYZZH', 'code' => 'fr'), + array('name' => $this->language->get('text_italy'), 'id' => 'APJ6JRA9NG5V4', 'code' => 'it'), + array('name' => $this->language->get('text_spain'), 'id' => 'A1RKKUPIHCS9HS', 'code' => 'es'), + array('name' => $this->language->get('text_united_kingdom'), 'id' => 'A1F83G8C2ARO7P', 'code' => 'uk'), + ); + + $marketplace_mapping = array( + 'uk' => 'A1F83G8C2ARO7P', + 'de' => 'A1PA6795UKMFR9', + 'fr' => 'A13V1IB3VIYZZH', + 'it' => 'APJ6JRA9NG5V4', + 'es' => 'A1RKKUPIHCS9HS', + ); + + if ($this->config->get('openbay_amazon_default_listing_marketplace')) { + $data['default_marketplaces'] = array($marketplace_mapping[$this->config->get('openbay_amazon_default_listing_marketplace')]); + } else { + $data['default_marketplaces'] = array(); + } + + $data['saved_marketplaces'] = isset($saved_listing_data['marketplaces']) ? (array)unserialize($saved_listing_data['marketplaces']) : false; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing_advanced', $data)); + } + + public function removeErrors() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->removeAdvancedErrors($product_id); + $this->session->data['success'] = 'Errors removed'; + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteSaved() { + if (!isset($this->request->get['product_id']) || !isset($this->request->get['var'])) { + return; + } + + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->deleteSaved($this->request->get['product_id'], $this->request->get['var']); + } + + public function uploadSaved() { + ob_start(); + $json = json_encode($this->uploadItems()); + ob_clean(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + private function uploadItems() { + $this->load->language('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $logger = new Log('amazon_product.log'); + + $logger->write('Uploading process started . '); + + $saved_products = $this->model_extension_openbay_amazon->getSavedProductsData(); + + if (empty($saved_products)) { + $logger->write('No saved listings found. Uploading canceled . '); + $result['status'] = 'error'; + $result['error_message'] = 'No saved listings. Nothing to upload. Aborting . '; + return $result; + } + + foreach($saved_products as $saved_product) { + $product_data_decoded = (array)json_decode($saved_product['data']); + + $catalog = defined(HTTPS_CATALOG) ? HTTPS_CATALOG : HTTP_CATALOG; + $response_data = array("response_url" => $catalog . 'index.php?route=extension/openbay/amazon/product'); + $category_data = array('category' => (string)$saved_product['category']); + $fields_data = array('fields' => (array)$product_data_decoded['fields']); + + $mp_array = !empty($saved_product['marketplaces']) ? (array)unserialize($saved_product['marketplaces']) : array(); + $marketplaces_data = array('marketplaces' => $mp_array); + + $product_data = array_merge($category_data, $fields_data, $response_data, $marketplaces_data); + $insertion_response = $this->openbay->amazon->insertProduct($product_data); + + $logger->write("Uploading product with data:" . print_r($product_data, true) . " + Got response:" . print_r($insertion_response, true)); + + if (!isset($insertion_response['status']) || $insertion_response['status'] == 'error') { + $details = isset($insertion_response['info']) ? $insertion_response['info'] : 'Unknown'; + $result['error_message'] = sprintf($this->language->get('error_upload_failed'), $saved_product['product_sku'], $details); + $result['status'] = 'error'; + break; + } + $logger->write('Product upload success'); + $this->model_extension_openbay_amazon->setProductUploaded($saved_product['product_id'], $insertion_response['insertion_id'], $saved_product['var']); + } + + if (!isset($result['status'])) { + $result['status'] = 'ok'; + $logger->write('Uploading process completed successfully . '); + } else { + $logger->write('Uploading process failed with message: ' . $result['error_message']); + } + return $result; + } + + public function parseTemplateAjax() { + $this->load->model('tool/image'); + + $log = new Log('amazon_product.log'); + + $json = array(); + + if (isset($this->request->get['xml'])) { + $request = array('template' => $this->request->get['xml'], 'version' => 2); + $response = $this->openbay->amazon->call("productv2/GetTemplateXml", $request); + if ($response) { + $template = $this->openbay->amazon->parseCategoryTemplate($response); + if ($template) { + $variation = isset($this->request->get['sku']) ? $this->request->get['sku'] : ''; + + if (isset($this->request->get['product_id'])) { + $template['fields'] = $this->fillDefaultValues($this->request->get['product_id'], $template['fields'], $variation); + } elseif (isset($this->request->get['edit_id'])) { + $template['fields'] = $this->fillSavedValues($this->request->get['edit_id'], $template['fields'], $variation); + } + + foreach($template['fields'] as $key => $field) { + if ($field['accepted']['type'] == 'image') { + if (empty($field['value'])) { + $template['fields'][$key]['thumb'] = ''; + } else { + $template['fields'][$key]['thumb'] = $this->model_tool_image->resize(str_replace(HTTPS_CATALOG . 'image/', '', $field['value']), 100, 100); + } + } + } + + $result = array( + "category" => $template['category'], + "fields" => $template['fields'], + "tabs" => $template['tabs'] + ); + } else { + $json_decoded = json_decode($response); + if ($json_decoded) { + $result = $json_decoded; + } else { + $result = array('status' => 'error'); + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed to parse template response: " . $response); + } + } + } else { + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed calling productv2/GetTemplateXml with params: " . print_r($request, true)); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + private function fillDefaultValues($product_id, $fields_array, $var = '') { + $this->load->model('catalog/product'); + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/amazon'); + + $openbay_settings = $this->model_setting_setting->getSetting('openbay_amazon'); + + $product_info = $this->model_catalog_product->getProduct($product_id); + $product_info['description'] = trim(utf8_encode(strip_tags(html_entity_decode($product_info['description']), "<br>"))); + $product_info['image'] = HTTPS_CATALOG . 'image/' . $product_info['image']; + + $tax_added = isset($openbay_settings['openbay_amazon_listing_tax_added']) ? $openbay_settings['openbay_amazon_listing_tax_added'] : 0; + $default_condition = isset($openbay_settings['openbay_amazon_listing_default_condition']) ? $openbay_settings['openbay_amazon_listing_default_condition'] : ''; + $product_info['price'] = number_format($product_info['price'] + $tax_added / 100 * $product_info['price'], 2, '.', ''); + + $defaults = array( + 'sku' => $product_info['sku'], + 'title' => $product_info['name'], + 'quantity' => $product_info['quantity'], + 'standardprice' => $product_info['price'], + 'description' => $product_info['description'], + 'mainimage' => $product_info['image'], + 'currency' => $this->config->get('config_currency'), + 'shippingweight' => number_format($product_info['weight'], 2, '.', ''), + 'conditiontype' => $default_condition, + ); + + $this->load->model('localisation/weight_class'); + $weight_class = $this->model_localisation_weight_class->getWeightClass($product_info['weight_class_id']); + if (!empty($weight_class)) { + $defaults['shippingweightunitofmeasure'] = $weight_class['unit']; + } + + $this->load->model('catalog/manufacturer'); + $manufacturer = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); + if (!empty($manufacturer)) { + $defaults['manufacturer'] = $manufacturer['name']; + $defaults['brand'] = $manufacturer['name']; + } + + $product_images = $this->model_catalog_product->getProductImages($product_id); + $image_index = 1; + foreach($product_images as $product_image) { + $defaults['pt' . $image_index] = HTTPS_CATALOG . 'image/' . $product_image['image']; + $image_index ++; + } + + if (!empty($product_info['upc'])) { + $defaults['type'] = 'UPC'; + $defaults['value'] = $product_info['upc']; + } else if (!empty($product_info['ean'])) { + $defaults['type'] = 'EAN'; + $defaults['value'] = $product_info['ean']; + } + + $meta_keywords = explode(',', $product_info['meta_keyword']); + foreach ($meta_keywords as $index => $meta_keyword) { + $defaults['searchterms' . $index] = trim($meta_keyword); + } + + if ($var !== '' && $this->openbay->addonLoad('openstock')) { + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $option = ''; + + foreach ($option_stocks as $option_iterator) { + if ($option_iterator['sku'] === $var) { + $option = $option_iterator; + break; + } + } + + if ($option != '') { + $defaults['sku'] = $option['sku']; + $defaults['quantity'] = $option['stock']; + $defaults['standardprice'] = number_format($option['price'] + $tax_added / 100 * $option['price'], 2, '.', ''); + $defaults['shippingweight'] = number_format($option['weight'], 2, '.', ''); + + if (!empty($option['image'])) { + $defaults['mainimage'] = HTTPS_CATALOG . 'image/' . $option['image']; + } + } + } + + if ($defaults['shippingweight'] <= 0) { + unset($defaults['shippingweight']); + unset($defaults['shippingweightunitofmeasure']); + } + + $filled_array = array(); + + foreach($fields_array as $field) { + + $value_array = array('value' => ''); + + if (isset($defaults[strtolower($field['name'])])) { + $value_array = array('value' => $defaults[strtolower($field['name'])]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + return $filled_array; + } + + private function fillSavedValues($product_id, $fields_array, $var = '') { + + $this->load->model('extension/openbay/amazon'); + $saved_listing = $this->model_extension_openbay_amazon->getProduct($product_id, $var); + + $decoded_data = (array)json_decode($saved_listing['data']); + $saved_fields = (array)$decoded_data['fields']; + + //Show current quantity instead of last uploaded + $saved_fields['Quantity'] = $this->model_extension_openbay_amazon->getProductQuantity($product_id, $var); + + $filled_array = array(); + + foreach($fields_array as $field) { + $value_array = array('value' => ''); + + if (isset($saved_fields[$field['name']])) { + $value_array = array('value' => $saved_fields[$field['name']]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + + return $filled_array; + } + + public function resetPending() { + $this->db->query("UPDATE `" . DB_PREFIX . "amazon_product` SET `status` = 'saved' WHERE `status` = 'uploaded'"); + } + + private function validateForm() { + return true; + } + + private function formatUrlsInText($text) { + $regex_url = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; + preg_match_all($regex_url, $text, $matches); + $used_patterns = array(); + foreach($matches[0] as $pattern) { + if (!array_key_exists($pattern, $used_patterns)) { + $used_patterns[$pattern]=true; + $text = str_replace($pattern, "<a target='_blank' href=" . $pattern . ">" . $pattern . "</a>", $text); + } + } + return $text; + } +} diff --git a/public/admin/controller/extension/openbay/amazonus.php b/public/admin/controller/extension/openbay/amazonus.php new file mode 100644 index 0000000..a6d79b3 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus.php @@ -0,0 +1,1040 @@ +<?php +class ControllerExtensionOpenbayAmazonus extends Controller { + public function install() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazonus_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazonus_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazonus_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazonus_product'); + + $this->model_extension_openbay_amazonus->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_amazonus->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/amazonus'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazonus'); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->amazonus->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/amazonus/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_subscription'] = $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['link_item_link'] = $this->url->link('extension/openbay/amazonus/itemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['link_stock_updates'] = $this->url->link('extension/openbay/amazonus/stockUpdates', 'user_token=' . $this->session->data['user_token'], true); + $data['link_saved_listings'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_listing'] = $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_linking'] = $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=amazonus'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus', $data)); + } + + public function stockUpdates() { + $this->load->language('extension/openbay/amazonus_stockupdates'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/stockUpdates', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $request_args = array(); + + if (isset($this->request->get['filter_date_start'])) { + $request_args['date_start'] = date("Y-m-d", strtotime($this->request->get['filter_date_start'])); + } else { + $request_args['date_start'] = date("Y-m-d"); + } + + if (isset($this->request->get['filter_date_end'])) { + $request_args['date_end'] = date("Y-m-d", strtotime($this->request->get['filter_date_end'])); + } else { + $request_args['date_end'] = date("Y-m-d"); + } + + $data['date_start'] = $request_args['date_start']; + $data['date_end'] = $request_args['date_end']; + + $xml = $this->openbay->amazonus->getStockUpdatesStatus($request_args); + $simple_xml_obj = simplexml_load_string($xml); + $data['table_data'] = array(); + + if ($simple_xml_obj !== false) { + $table_data = array(); + + foreach($simple_xml_obj->update as $update_node) { + $row = array( + 'date_requested' => (string)$update_node->date_requested, + 'date_updated' => (string)$update_node->date_updated, + 'status' => (string)$update_node->status, + ); + + $data_items = array(); + + foreach($update_node->data->product as $product_node) { + $data_items[] = array( + 'sku' => (string)$product_node->sku, + 'stock' => (int)$product_node->stock + ); + } + + $row['data'] = $data_items; + $table_data[(int)$update_node->ref] = $row; + } + + $data['table_data'] = $table_data; + } else { + $data['error'] = $data['error_api_connection']; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_stock_updates', $data)); + } + + public function subscription() { + $this->load->language('extension/openbay/amazonus_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $response = simplexml_load_string($this->openbay->amazonus->call('plans/getPlans')); + + $data['plans'] = array(); + + if ($response) { + foreach ($response->Plan as $plan) { + $data['plans'][] = array( + 'title' => (string)$plan->Title, + 'description' => (string)$plan->Description, + 'order_frequency' => (string)$plan->OrderFrequency, + 'product_listings' => (string)$plan->ProductListings, + 'bulk_listing' => (string)$plan->BulkListing, + 'price' => (string)$plan->Price, + ); + } + } + + $response = simplexml_load_string($this->openbay->amazonus->call('plans/getUsersPlans')); + + $plan = false; + + if ($response) { + $plan = array( + 'merchant_id' => (string)$response->MerchantId, + 'user_status' => (string)$response->UserStatus, + 'title' => (string)$response->Title, + 'description' => (string)$response->Description, + 'price' => (string)$response->Price, + 'order_frequency' => (string)$response->OrderFrequency, + 'product_listings' => (string)$response->ProductListings, + 'listings_remain' => (string)$response->ListingsRemain, + 'listings_reserved' => (string)$response->ListingsReserved, + 'bulk_listing' => (string)$response->BulkListing, + ); + } + + $data['user_plan'] = $plan; + $data['link_change_plan'] = $this->openbay->amazonus->getServer() . 'account/changePlan/?token=' . $this->config->get('openbay_amazonus_token'); + $data['link_change_seller'] = $this->openbay->amazonus->getServer() . 'account/changeSellerId/?token=' . $this->config->get('openbay_amazonus_token'); + $data['link_register'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=subscription&utm_campaign=amazonus'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_subscription', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/amazonus_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazonus'); + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $settings = array_merge($settings, $this->request->post); + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + + $this->config->set('openbay_amazonus_token', $this->request->post['openbay_amazonus_token']); + $this->config->set('openbay_amazonus_encryption_key', $this->request->post['openbay_amazonus_encryption_key']); + $this->config->set('openbay_amazonus_encryption_iv', $this->request->post['openbay_amazonus_encryption_iv']); + + $this->openbay->amazonus->setEncryptionKey($this->request->post['openbay_amazonus_encryption_key']); + $this->openbay->amazonus->setEncryptionIv($this->request->post['openbay_amazonus_encryption_iv']); + + if (!empty($this->request->post['openbay_amazonus_token']) && !empty($this->request->post['openbay_amazonus_encryption_key']) && !empty($this->request->post['openbay_amazonus_encryption_iv'])) { + $this->model_extension_openbay_amazonus->verifyConfig($settings); + } + + $this->session->data['success'] = $this->language->get('text_settings_updated'); + $this->response->redirect($this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['openbay_amazonus_status'] = isset($settings['openbay_amazonus_status']) ? $settings['openbay_amazonus_status'] : ''; + $data['openbay_amazonus_token'] = isset($settings['openbay_amazonus_token']) ? $settings['openbay_amazonus_token'] : ''; + $data['openbay_amazonus_encryption_key'] = isset($settings['openbay_amazonus_encryption_key']) ? $settings['openbay_amazonus_encryption_key'] : ''; + $data['openbay_amazonus_encryption_iv'] = isset($settings['openbay_amazonus_encryption_iv']) ? $settings['openbay_amazonus_encryption_iv'] : ''; + $data['openbay_amazonus_listing_tax_added'] = isset($settings['openbay_amazonus_listing_tax_added']) ? $settings['openbay_amazonus_listing_tax_added'] : '0.00'; + $data['openbay_amazonus_order_tax'] = isset($settings['openbay_amazonus_order_tax']) ? $settings['openbay_amazonus_order_tax'] : '00'; + $data['openbay_amazonus_default_listing_marketplace'] = isset($settings['openbay_amazonus_default_listing_marketplace']) ? $settings['openbay_amazonus_default_listing_marketplace'] : ''; + $data['openbay_amazonus_listing_default_condition'] = isset($settings['openbay_amazonus_listing_default_condition']) ? $settings['openbay_amazonus_listing_default_condition'] : ''; + + $data['carriers'] = $this->openbay->amazonus->getCarriers(); + $data['openbay_amazonus_default_carrier'] = isset($settings['openbay_amazonus_default_carrier']) ? $settings['openbay_amazonus_default_carrier'] : ''; + + $unshipped_status_id = isset($settings['openbay_amazonus_order_status_unshipped']) ? $settings['openbay_amazonus_order_status_unshipped'] : ''; + $partially_shipped_status_id = isset($settings['openbay_amazonus_order_status_partially_shipped']) ? $settings['openbay_amazonus_order_status_partially_shipped'] : ''; + $shipped_status_id = isset($settings['openbay_amazonus_order_status_shipped']) ? $settings['openbay_amazonus_order_status_shipped'] : ''; + $canceled_status_id = isset($settings['openbay_amazonus_order_status_canceled']) ? $settings['openbay_amazonus_order_status_canceled'] : ''; + + $amazonus_order_statuses = array( + 'unshipped' => array('name' => $this->language->get('text_unshipped'), 'order_status_id' => $unshipped_status_id), + 'partially_shipped' => array('name' => $this->language->get('text_partially_shipped'), 'order_status_id' => $partially_shipped_status_id), + 'shipped' => array('name' => $this->language->get('text_shipped'), 'order_status_id' => $shipped_status_id), + 'canceled' => array('name' => $this->language->get('text_canceled'), 'order_status_id' => $canceled_status_id), + ); + + $data['openbay_amazonus_order_customer_group'] = isset($settings['openbay_amazonus_order_customer_group']) ? $settings['openbay_amazonus_order_customer_group'] : ''; + + $data['amazonus_order_statuses'] = $amazonus_order_statuses; + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['subscription_url'] = $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['itemLinks_url'] = $this->url->link('extension/openbay/amazonus_product/linkItems', 'user_token=' . $this->session->data['user_token'], true); + $data['openbay_amazonus_notify_admin'] = isset($settings['openbay_amazonus_notify_admin']) ? $settings['openbay_amazonus_notify_admin'] : ''; + $data['link_signup'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=amazonus'; + + $api_checked = false; + $api_status = false; + $api_auth = false; + + if (!empty($data['openbay_amazonus_token']) && !empty($data['openbay_amazonus_encryption_key']) && !empty($data['openbay_amazonus_encryption_iv'])) { + $response = $this->openbay->amazonus->call('ping/info'); + + $api_checked = true; + + if (!empty($response)) { + $ping_info = simplexml_load_string($response); + + if ($ping_info === false) { + /** + * The data from the API could not be extracted from the XML + */ + } else { + $api_status = ((string)$ping_info->Api_status == 'ok') ? true : false; + $api_auth = ((string)$ping_info->Auth == 'true') ? true : false; + } + } + } + + $data['api_status'] = $api_status; + $data['api_auth'] = $api_auth; + $data['api_checked'] = $api_checked; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_settings', $data)); + } + + public function itemLinks() { + $this->load->language('extension/openbay/amazonus_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_item_links', $data)); + } + + public function savedListings() { + $this->load->language('extension/openbay/amazonus_listingsaved'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + $this->load->model('extension/openbay/amazonus'); + $saved_products = $this->model_extension_openbay_amazonus->getSavedProducts(); + + $data['saved_products'] = array(); + + foreach($saved_products as $saved_product) { + $data['saved_products'][] = array( + 'product_id' => $saved_product['product_id'], + 'product_name' => $saved_product['product_name'], + 'product_model' => $saved_product['product_model'], + 'product_sku' => $saved_product['product_sku'], + 'amazon_sku' => $saved_product['amazonus_sku'], + 'var' => $saved_product['var'], + 'edit_link' => $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $saved_product['product_id'] . '&sku=' . $saved_product['var'], true), + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_saved_listings', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/amazonus')) { + $this->error = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + return true; + } + + return false; + } + + public function getVariants() { + $variants = array(); + + if ($this->openbay->addonLoad('openstock') && isset($this->request->get['product_id'])) { + $this->load->model('extension/module/openstock'); + $this->load->model('tool/image'); + $variants = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + } + + if (empty($variants)) { + $variants = false; + } else { + foreach ($variants as $key => $variant) { + if ($variant['sku'] == '') { + unset($variants[$key]); + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($variants)); + } + + public function addLink() { + if (isset($this->request->get['product_id']) && isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazonus'); + + $amazon_sku = $this->request->get['amazon_sku']; + $product_id = $this->request->get['product_id']; + $var = isset($this->request->get['var']) ? $this->request->get['var'] : ''; + + $this->model_extension_openbay_amazonus->linkProduct($amazon_sku, $product_id, $var); + + $logger = new Log('amazonus_stocks.log'); + $logger->write('addItemLink() called for product id: ' . $product_id . ', amazon sku: ' . $amazon_sku . ', var: ' . $var); + + if ($var != '' && $this->openbay->addonLoad('openstock')) { + $logger->write('Using openStock'); + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $quantity_data = array(); + + foreach($option_stocks as $option_stock) { + if (isset($option_stock['sku']) && $option_stock['sku'] == $var) { + $quantity_data[$amazon_sku] = $option_stock['stock']; + break; + } + } + + if (!empty($quantity_data)) { + $logger->write('Updating quantities with data: ' . print_r($quantity_data, true)); + $this->openbay->amazonus->updateQuantities($quantity_data); + } else { + $logger->write('No quantity data will be posted . '); + } + } else { + $this->openbay->amazonus->putStockUpdateBulk(array($product_id)); + } + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function deleteLink() { + if (isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazonus'); + + $amazon_sku = $this->request->get['amazon_sku']; + + $this->model_extension_openbay_amazonus->removeProductLink($amazon_sku); + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getLinks() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + + $itemLinks = $this->model_extension_openbay_amazonus->getProductLinks(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($itemLinks)); + } + + public function getUnlinked() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + + $unlinkedProducts = $this->model_extension_openbay_amazonus->getUnlinkedProducts(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($unlinkedProducts)); + } + + public function doBulkList() { + $this->load->language('extension/openbay/amazonus_listing'); + + if (empty($this->request->post['products'])) { + $json = array( + 'message' => $this->language->get('error_not_searched'), + ); + } else { + $this->load->model('extension/openbay/amazonus_listing'); + + $delete_search_results = array(); + + $bulk_list_products = array(); + + foreach ($this->request->post['products'] as $product_id => $asin) { + $delete_search_results[] = $product_id; + + if (!empty($asin) && in_array($product_id, $this->request->post['product_ids'])) { + $bulk_list_products[$product_id] = $asin; + } + } + + $status = false; + + if ($bulk_list_products) { + $data = array(); + + $data['products'] = $bulk_list_products; + + if (!empty($this->request->post['start_selling'])) { + $data['start_selling'] = $this->request->post['start_selling']; + } + + if (!empty($this->request->post['condition']) && !empty($this->request->post['condition_note'])) { + $data['condition'] = $this->request->post['condition']; + $data['condition_note'] = $this->request->post['condition_note']; + } + + $status = $this->model_extension_openbay_amazonus_listing->doBulkListing($data); + + if ($status) { + $message = $this->language->get('text_products_sent'); + + if ($delete_search_results) { + $this->model_extension_openbay_amazonus_listing->deleteSearchResults($delete_search_results); + } + } else { + $message = $this->language->get('error_sending_products'); + } + } else { + $message = $this->language->get('error_no_products_selected'); + } + + $json = array( + 'status' => $status, + 'message' => $message, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkSearch() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_bulk_listing'); + + $json = array(); + $search_data = array(); + + if (!empty($this->request->post['product_ids'])) { + foreach ($this->request->post['product_ids'] as $product_id) { + $product = $this->model_catalog_product->getProduct($product_id); + + if (empty($product['sku'])) { + $json[$product_id] = array( + 'error' => $this->language->get('error_product_sku') + ); + } + + $key = ''; + + $id_types = array('isbn', 'upc', 'ean', 'jan', 'sku'); + + foreach ($id_types as $id_type) { + if (!empty($product[$id_type])) { + $key = $id_type; + break; + } + } + + if (!$key) { + $json[$product_id] = array( + 'error' => $this->language->get('error_searchable_fields') + ); + } + + if (!isset($json[$product_id])) { + $search_data[$key][] = array( + 'product_id' => $product['product_id'], + 'value' => trim($product[$id_type]), + ); + + $json[$product_id] = array( + 'success' => $this->language->get('text_searching') + ); + } + } + } + + if ($search_data) { + $this->model_extension_openbay_amazonus_listing->doBulkSearch($search_data); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bulkListProducts() { + $this->load->language('extension/openbay/amazonus_bulk_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazonus->call('ping/info')); + + $bulk_listing_status = false; + + if ($ping_info) { + $bulk_listing_status = ((string)$ping_info->BulkListing == 'true') ? true : false; + } + + $data['bulk_listing_status'] = $bulk_listing_status; + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if ($bulk_listing_status) { + $data['link_search'] = $this->url->link('extension/openbay/amazonus/doBulkSearch', 'user_token=' . $this->session->data['user_token'], true); + + $data['default_condition'] = $this->config->get('openbay_amazonus_listing_default_condition'); + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + if (!empty($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $filter = array(); + + $filter['start'] = ($page - 1) * $this->config->get('config_limit_admin'); + $filter['limit'] = $this->config->get('config_limit_admin'); + + $results = $this->model_extension_openbay_amazonus->getProductSearch($filter); + $product_total = $this->model_extension_openbay_amazonus->getProductSearchTotal($filter); + + $data['products'] = array(); + + foreach ($results as $result) { + $product = $this->model_catalog_product->getProduct($result['product_id']); + + if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) { + $image = $this->model_tool_image->resize($product['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + if ($result['status'] == 'searching') { + $search_status = $this->language->get('text_searching'); + } else if ($result['status'] == 'finished') { + $search_status = $this->language->get('text_finished'); + } else { + $search_status = '-'; + } + + $href = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true); + + $search_results = array(); + + if ($result['data']) { + foreach ($result['data'] as $search_result) { + + $link = 'https://www.amazon.com/dp/' . $search_result['asin'] . '/'; + + $search_results[] = array( + 'title' => $search_result['title'], + 'asin' => $search_result['asin'], + 'href' => $link, + ); + } + } + + $data['products'][] = array( + 'product_id' => $product['product_id'], + 'href' => $href, + 'name' => $product['name'], + 'model' => $product['model'], + 'image' => $image, + 'matches' => $result['matches'], + 'search_status' => $search_status, + 'search_results' => $search_results, + ); + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_bulk_listing', $data)); + } + + public function bulkLinking() { + $this->load->language('extension/openbay/amazonus_bulk_linking'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/amazonus'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazonus->call('ping/info')); + + $bulk_linking_status = false; + if ($ping_info) { + $bulk_linking_status = ((string)$ping_info->BulkLinking == 'true') ? true : false; + } + + $data['bulk_linking_status'] = $bulk_linking_status; + + $total_linked = $this->model_extension_openbay_amazonus->getTotalUnlinkedItemsFromReport(); + + if (isset($this->request->get['linked_item_page'])){ + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 25; + } + + $data['cancel_report_link'] = ''; + + if (isset($this->request->get['cancel_report']) && $this->request->get['cancel_report'] == 1) { + $this->load->model('setting/setting'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + $settings['openbay_amazonus_processing_listing_reports'] = ''; + + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + + $this->response->redirect($this->url->link('extension/openbay/amazonus/bulklinking', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['cancel_report_link'] = $this->url->link('extension/openbay/amazonus/bulklinking', 'cancel_report=1&user_token=' . $this->session->data['user_token'], true); + } + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = $linked_item_limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($linked_item_page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) > ($total_linked - $this->config->get('config_limit_admin'))) ? $total_linked : ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total_linked, ceil($total_linked / $this->config->get('config_limit_admin'))); + + $results = $this->model_extension_openbay_amazonus->getUnlinkedItemsFromReport($linked_item_limit, $linked_item_page); + + $products = array(); + + foreach ($results as $result) { + $products[] = array( + 'asin' => $result['asin'], + 'href_amazon' => 'https://www.amazon.com/dp/' . $result['asin'] . '/', + 'amazon_sku' => $result['amazon_sku'], + 'amazon_quantity' => $result['amazon_quantity'], + 'amazon_price' => $result['amazon_price'], + 'name' => $result['name'], + 'sku' => $result['sku'], + 'quantity' => $result['quantity'], + 'combination' => $result['combination'], + 'product_id' => $result['product_id'], + 'var' => $result['sku'], + 'href_product' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'], true), + ); + } + + $data['unlinked_products'] = $products; + + $data['marketplace_processing'] = $this->config->get('openbay_amazonus_processing_listing_reports'); + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + $data['link_load_listings'] = $this->url->link('extension/openbay/amazonus/loadListingReport', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_bulk_linking', $data)); + } + + public function loadListingReport() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->language('extension/openbay/amazonus_bulk_linking'); + + $this->model_extension_openbay_amazonus->deleteListingReports(); + + $request_data = array('response_url' => HTTPS_CATALOG . 'index.php?route=extension/openbay/amazonus/listingreport'); + + $response = $this->openbay->amazonus->call('report/listing', $request_data); + + $response = json_decode($response, 1); + + $json = array(); + $json['status'] = $response['status']; + + if ($json['status']) { + $json['message'] = $this->language->get('text_report_requested'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + $settings['openbay_amazonus_processing_listing_reports'] = true; + + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + } else { + $json['message'] = $this->language->get('text_report_request_failed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkLinking() { + $this->load->model('extension/openbay/amazonus'); + + $links = array(); + $skus = array(); + + if (!empty($this->request->post['link'])) { + foreach ($this->request->post['link'] as $link) { + if (!empty($link['product_id'])) { + $links[] = $link; + $skus[] = $link['amazon_sku']; + } + } + } + + if (!empty($links)) { + foreach ($links as $link) { + $this->model_extension_openbay_amazonus->linkProduct($link['amazon_sku'], $link['product_id'], $link['sku']); + } + + $this->model_extension_openbay_amazonus->updateAmazonSkusQuantities($skus); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('ok'))); + } + + public function doFullStockSync() { + /** + * This is used if you ever need to force a complete update of your stock levels to Amazon. + * It will get ALL products in your store then lookup any linked ones before sending to the API. + * + * This call can put serious load on your server if you have a lot of products. + * It will make a lot of database queries so ensure your php memory limit is set high enough. + */ + set_time_limit(0); + + $product_array = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product`")->rows; + + $bulk_array = array(); + + foreach ($product_array as $product) { + $bulk_array[] = $product['product_id']; + } + + $this->openbay->amazonus->putStockUpdateBulk($bulk_array); + } +} diff --git a/public/admin/controller/extension/openbay/amazonus_listing.php b/public/admin/controller/extension/openbay/amazonus_listing.php new file mode 100644 index 0000000..a5ea2da --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus_listing.php @@ -0,0 +1,592 @@ +<?php +class ControllerExtensionOpenbayAmazonusListing extends Controller{ + public function create() { + $this->load->language('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if ($this->request->post) { + $result = $this->model_extension_openbay_amazonus_listing->simpleListing($this->request->post); + + if ($result['status'] === 1) { + $this->session->data['success'] = $this->language->get('text_product_sent'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $this->session->data['error'] = sprintf($this->language->get('text_product_not_sent'), $result['message']); + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->post['product_id'] . $url, true)); + } + } + + if (isset($this->request->get['product_id'])) { + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if (empty($product_info)) { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $listing_status = $this->model_extension_openbay_amazonus->getProductStatus($this->request->get['product_id']); + + if ($listing_status === 'processing' || $listing_status === 'ok') { + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } else if ($listing_status === 'error_advanced' || $listing_status === 'saved' || $listing_status === 'error_few') { + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['url_search'] = $this->url->link('extension/openbay/amazonus_listing/search', 'user_token=' . $this->session->data['user_token'], true); + $data['url_advanced'] = $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true); + + $data['button_search'] = $this->language->get('button_search'); + $data['button_new'] = $this->language->get('button_new'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_amazon_price'] = $this->language->get('button_amazon_price'); + $data['button_list'] = $this->language->get('button_list'); + $data['heading_title'] = $this->language->get('heading_title'); + $data['text_not_in_catalog'] = $this->language->get('text_not_in_catalog'); + $data['text_no_results'] = $this->language->get('text_no_results'); + $data['button_view_on_amazon'] = $this->language->get('button_view_on_amazon'); + $data['text_list'] = $this->language->get('text_list'); + $data['text_placeholder_search'] = $this->language->get('text_placeholder_search'); + $data['text_placeholder_condition'] = $this->language->get('text_placeholder_condition'); + $data['column_image'] = $this->language->get('column_image'); + $data['column_asin'] = $this->language->get('column_asin'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_price'] = $this->language->get('column_price'); + $data['column_action'] = $this->language->get('column_action'); + $data['entry_sku'] = $this->language->get('entry_sku'); + $data['entry_condition'] = $this->language->get('entry_condition'); + $data['entry_condition_note'] = $this->language->get('entry_condition_note'); + $data['entry_price'] = $this->language->get('entry_price'); + $data['entry_sale_price'] = $this->language->get('entry_sale_price'); + $data['entry_sale_date'] = $this->language->get('entry_sale_date'); + $data['entry_quantity'] = $this->language->get('entry_quantity'); + $data['entry_start_selling'] = $this->language->get('entry_start_selling'); + $data['entry_restock_date'] = $this->language->get('entry_restock_date'); + $data['entry_from'] = $this->language->get('entry_from'); + $data['entry_to'] = $this->language->get('entry_to'); + $data['help_restock_date'] = $this->language->get('help_restock_date'); + $data['help_sku'] = $this->language->get('help_sku'); + $data['help_sale_price'] = $this->language->get('help_sale_price'); + $data['tab_required'] = $this->language->get('tab_required'); + $data['tab_additional'] = $this->language->get('tab_additional'); + $data['error_price'] = $this->language->get('error_price'); + $data['error_sku'] = $this->language->get('error_sku'); + $data['error_stock'] = $this->language->get('error_stock'); + + $data['form_action'] = $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'], true); + + $data['sku'] = trim($product_info['sku']); + + if ($this->config->get('openbay_amazonus_listing_tax_added')) { + $data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazonus_listing_tax_added') / 100); + } else { + $data['price'] = $product_info['price']; + } + + $data['listing_errors'] = array(); + + if ($listing_status == 'error_quick') { + $data['listing_errors'] = $this->model_extension_openbay_amazonus->getProductErrors($product_info['product_id'], 3); + } + + $data['price'] = number_format($data['price'], 2, '.', ''); + $data['quantity'] = $product_info['quantity']; + $data['product_id'] = $product_info['product_id']; + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['default_condition'] = $this->config->get('openbay_amazonus_listing_default_condition'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . $url, true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing', $data)); + } + + public function edit() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $this->load->language('extension/openbay/amazonus_listing'); + + $this->document->setTitle($this->language->get('text_edit_heading')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true), + 'text' => $this->language->get('text_edit_heading'), + ); + + $status = $this->model_extension_openbay_amazonus->getProductStatus($product_id); + + if ($status === false) { + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + return; + } + + $data['product_links'] = $this->model_extension_openbay_amazonus->getProductLinks($product_id); + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + if ($status == 'ok' || $status == 'linked') { + $data['url_create_new'] = $this->url->link('extension/openbay/amazonus_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['url_delete_links'] = $this->url->link('extension/openbay/amazonus_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + } + + if ($status == 'saved') { + $data['has_saved_listings'] = true; + } else { + $data['has_saved_listings'] = false; + } + + $data['url_saved_listings'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['text_edit_heading'] = $this->language->get('text_edit_heading'); + $data['text_product_links'] = $this->language->get('text_product_links'); + $data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings'); + $data['button_create_new_listing'] = $this->language->get('button_create_new_listing'); + $data['button_remove_links'] = $this->language->get('button_remove_links'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_saved_listings'] = $this->language->get('button_saved_listings'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_model'] = $this->language->get('column_model'); + $data['column_combination'] = $this->language->get('column_combination'); + $data['column_sku'] = $this->language->get('column_sku'); + $data['column_amazon_sku'] = $this->language->get('column_amazon_sku'); + $data['column_sku_variant'] = $this->language->get('column_sku_variant'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing_edit', $data)); + } + + public function createNew() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->deleteProduct($product_id); + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteLinks() { + $this->load->language('extension/openbay/amazonus_listing'); + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->load->model('extension/openbay/amazonus'); + + $links = $this->model_extension_openbay_amazonus->getProductLinks($product_id); + foreach ($links as $link) { + $this->model_extension_openbay_amazonus->removeProductLink($link['amazonus_sku']); + } + + $this->model_extension_openbay_amazonus->deleteProduct($product_id); + $this->session->data['success'] = $this->language->get('text_links_removed'); + + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + public function search() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_listing'); + + $error = ''; + + if (empty($this->request->post['search_string'])) { + $error = $this->language->get('error_text_missing'); + } + + if ($error) { + $response = array( + 'data' => '', + 'error' => $error, + ); + } else { + $response = array( + 'data' => $this->model_extension_openbay_amazonus_listing->search($this->request->post['search_string']), + 'error' => '', + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function bestPrice() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_listing'); + + $error = ''; + + if (empty($this->request->post['asin'])) { + $error = $this->language->get('error_missing_asin'); + } + + if (empty($this->request->post['condition'])) { + $error = $this->language->get('error_condition_missing'); + } + + if ($error) { + $response = array( + 'data' => '', + 'error' => $error, + ); + } else { + $best_price = $this->model_extension_openbay_amazonus_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition']); + + if ($best_price) { + $response = array( + 'data' => $best_price, + 'error' => '', + ); + } else { + $response = array( + 'data' => '', + 'error' => $this->language->get('error_amazonus_price'), + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getProductByAsin() { + $this->load->model('extension/openbay/amazonus_listing'); + + $data = $this->model_extension_openbay_amazonus_listing->getProductByAsin($this->request->post['asin']); + + $response = array( + 'title' => (string)$data['ItemAttributes']['Title'], + 'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL']) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getBrowseNodes() { + $this->load->model('extension/openbay/amazonus_listing'); + + $data = array( + 'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''), + ); + + $response = $this->model_extension_openbay_amazonus_listing->getBrowseNodes($data); + + $this->response->setOutput($response); + } +} diff --git a/public/admin/controller/extension/openbay/amazonus_product.php b/public/admin/controller/extension/openbay/amazonus_product.php new file mode 100644 index 0000000..ab4f488 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus_product.php @@ -0,0 +1,559 @@ +<?php +class ControllerExtensionOpenbayAmazonusProduct extends Controller{ + public function index() { + $this->load->language('catalog/product'); + $this->load->language('extension/openbay/amazonus_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_title_advanced'), + ); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + die('No product id'); + } + + if (isset($this->request->get['sku'])) { + $variation = $this->request->get['sku']; + } else { + $variation = ''; + } + $data['variation'] = $variation; + $data['errors'] = array(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $data_array = $this->request->post; + + $this->model_extension_openbay_amazonus->saveProduct($product_id, $data_array); + + if ($data_array['upload_after'] === 'true') { + $upload_result = $this->uploadItems(); + if ($upload_result['status'] == 'ok') { + $this->session->data['success'] = $this->language->get('text_uploaded'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $data['errors'][] = Array('message' => $upload_result['error_message']); + } + } else { + $this->session->data['success'] = $this->language->get('text_saved_local'); + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $saved_listing_data = $this->model_extension_openbay_amazonus->getProduct($product_id, $variation); + if (empty($saved_listing_data)) { + $listing_saved = false; + } else { + $listing_saved = true; + } + + $errors = $this->model_extension_openbay_amazonus->getProductErrors($product_id); + foreach($errors as $error) { + $error['message'] = 'Error for SKU: "' . $error['sku'] . '" - ' . $this->formatUrlsInText($error['message']); + $data['errors'][] = $error; + } + if (!empty($errors)) { + $data['has_listing_errors'] = true; + } else { + $data['has_listing_errors'] = false; + } + + $product_info = $this->model_catalog_product->getProduct($product_id); + $data['listing_name'] = $product_info['name'] . " : " . $product_info['model']; + $data['listing_sku'] = $product_info['sku']; + $data['listing_url'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + + if ($listing_saved) { + $data['edit_product_category'] = $saved_listing_data['category']; + } else { + $data['edit_product_category'] = ''; + } + + $data['amazonus_categories'] = array(); + + $amazonus_templates = $this->openbay->amazonus->getCategoryTemplates(); + + foreach($amazonus_templates as $template) { + $template = (array)$template; + $category_data = array( + 'friendly_name' => $template['friendly_name'], + 'name' => $template['name'], + 'template' => $template['xml'] + ); + $data['amazonus_categories'][] = $category_data; + } + + if ($listing_saved) { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazonus_product/parseTemplateAjax&edit_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazonus_product/parseTemplateAjax&product_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['url_remove_errors'] = $this->url->link('extension/openbay/amazonus_product/removeErrors', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['cancel_url'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['saved_listings_url'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['main_url'] = $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['user_token'] = $this->session->data['user_token']; + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if ($this->openbay->addonLoad('openstock')) { + $this->load->model('extension/module/openstock'); + $data['options'] = $this->model_setting_module_openstock->getVariants($product_id); + } else { + $data['options'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing_advanced', $data)); + } + + public function removeErrors() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + 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']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->removeAdvancedErrors($product_id); + $this->session->data['success'] = 'Errors removed'; + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteSaved() { + if (!isset($this->request->get['product_id']) || !isset($this->request->get['var'])) { + return; + } + + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->deleteSaved($this->request->get['product_id'], $this->request->get['var']); + } + + public function uploadSaved() { + ob_start(); + $json = json_encode($this->uploadItems()); + ob_clean(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + private function uploadItems() { + $this->load->language('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $logger = new Log('amazonus_product.log'); + + $logger->write('Uploading process started . '); + + $saved_products = $this->model_extension_openbay_amazonus->getSavedProductsData(); + + if (empty($saved_products)) { + $logger->write('No saved listings found. Uploading canceled . '); + $result['status'] = 'error'; + $result['error_message'] = 'No saved listings. Nothing to upload. Aborting . '; + return $result; + } + + foreach($saved_products as $saved_product) { + $product_data_decoded = (array)json_decode($saved_product['data']); + + $catalog = defined(HTTPS_CATALOG) ? HTTPS_CATALOG : HTTP_CATALOG; + $response_data = array("response_url" => $catalog . 'index.php?route=extension/openbay/amazonus/product'); + $category_data = array('category' => (string)$saved_product['category']); + $fields_data = array('fields' => (array)$product_data_decoded['fields']); + + $mp_array = array(); //Amazon US does not have marketplace selection + $marketplaces_data = array('marketplaces' => $mp_array); + + $product_data = array_merge($category_data, $fields_data, $response_data, $marketplaces_data); + $insertion_response = $this->openbay->amazonus->insertProduct($product_data); + + $logger->write("Uploading product with data:" . print_r($product_data, true) . " + Got response:" . print_r($insertion_response, true)); + + if (!isset($insertion_response['status']) || $insertion_response['status'] == 'error') { + $details = isset($insertion_response['info']) ? $insertion_response['info'] : 'Unknown'; + $result['error_message'] = sprintf($this->language->get('error_upload_failed'), $saved_product['product_sku'], $details); + $result['status'] = 'error'; + break; + } + $logger->write('Product upload success'); + $this->model_extension_openbay_amazonus->setProductUploaded($saved_product['product_id'], $insertion_response['insertion_id'], $saved_product['var']); + } + + if (!isset($result['status'])) { + $result['status'] = 'ok'; + $logger->write('Uploading process completed successfully . '); + } else { + $logger->write('Uploading process failed with message: ' . $result['error_message']); + } + return $result; + } + + public function parseTemplateAjax() { + $this->load->model('tool/image'); + $log = new Log('amazonus_product.log'); + + $result = array(); + + if (isset($this->request->get['xml'])) { + $request = array('template' => $this->request->get['xml'], 'version' => 2); + $response = $this->openbay->amazonus->call("productv2/GetTemplateXml", $request); + if ($response) { + $template = $this->openbay->amazonus->parseCategoryTemplate($response); + if ($template) { + $variation = isset($this->request->get['sku']) ? $this->request->get['sku'] : ''; + + if (isset($this->request->get['product_id'])) { + $template['fields'] = $this->fillDefaultValues($this->request->get['product_id'], $template['fields'], $variation); + } elseif (isset($this->request->get['edit_id'])) { + $template['fields'] = $this->fillSavedValues($this->request->get['edit_id'], $template['fields'], $variation); + } + + foreach($template['fields'] as $key => $field) { + if ($field['accepted']['type'] == 'image') { + if (empty($field['value'])) { + $template['fields'][$key]['thumb'] = ''; + } else { + $template['fields'][$key]['thumb'] = $this->model_tool_image->resize(str_replace(HTTPS_CATALOG . 'image/', '', $field['value']), 100, 100); + } + } + } + + $result = array( + "category" => $template['category'], + "fields" => $template['fields'], + "tabs" => $template['tabs'] + ); + } else { + $json_decoded = json_decode($response); + if ($json_decoded) { + $result = $json_decoded; + } else { + $result = array('status' => 'error'); + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed to parse template response: " . $response); + } + } + } else { + $log->write("admin/openbay/amazonus_product/parseTemplateAjax failed calling productv2/GetTemplateXml with params: " . print_r($request, true)); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + private function fillDefaultValues($product_id, $fields_array, $var = '') { + $this->load->model('catalog/product'); + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/amazonus'); + + $openbay_settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + + $product_info = $this->model_catalog_product->getProduct($product_id); + $product_info['description'] = trim(utf8_encode(strip_tags(html_entity_decode($product_info['description']), "<br>"))); + $product_info['image'] = HTTPS_CATALOG . 'image/' . $product_info['image']; + + $tax_added = isset($openbay_settings['openbay_amazonus_listing_tax_added']) ? $openbay_settings['openbay_amazonus_listing_tax_added'] : 0; + $default_condition = isset($openbay_settings['openbay_amazonus_listing_default_condition']) ? $openbay_settings['openbay_amazonus_listing_default_condition'] : ''; + $product_info['price'] = number_format($product_info['price'] + $tax_added / 100 * $product_info['price'], 2, '.', ''); + + /*Key must be lowecase */ + $defaults = array( + 'sku' => $product_info['sku'], + 'title' => $product_info['name'], + 'quantity' => $product_info['quantity'], + 'standardprice' => $product_info['price'], + 'description' => $product_info['description'], + 'mainimage' => $product_info['image'], + 'currency' => $this->config->get('config_currency'), + 'shippingweight' => number_format($product_info['weight'], 2, '.', ''), + 'conditiontype' => $default_condition, + ); + + $this->load->model('localisation/weight_class'); + $weight_class = $this->model_localisation_weight_class->getWeightClass($product_info['weight_class_id']); + if (!empty($weight_class)) { + $defaults['shippingweightunitofmeasure'] = $weight_class['unit']; + } + + $this->load->model('catalog/manufacturer'); + $manufacturer = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); + if (!empty($manufacturer)) { + $defaults['manufacturer'] = $manufacturer['name']; + $defaults['brand'] = $manufacturer['name']; + } + + $product_images = $this->model_catalog_product->getProductImages($product_id); + $image_index = 1; + foreach($product_images as $product_image) { + $defaults['pt' . $image_index] = HTTPS_CATALOG . 'image/' . $product_image['image']; + $image_index ++; + } + + if (!empty($product_info['upc'])) { + $defaults['type'] = 'UPC'; + $defaults['value'] = $product_info['upc']; + } else if (!empty($product_info['ean'])) { + $defaults['type'] = 'EAN'; + $defaults['value'] = $product_info['ean']; + } + + $meta_keywords = explode(',', $product_info['meta_keyword']); + foreach ($meta_keywords as $index => $meta_keyword) { + $defaults['searchterms' . $index] = trim($meta_keyword); + } + + if ($var !== '' && $this->openbay->addonLoad('openstock')) { + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $option = ''; + foreach ($option_stocks as $option_iterator) { + if ($option_iterator['sku'] === $var) { + $option = $option_iterator; + break; + } + } + + if ($option != null) { + $defaults['sku'] = $option['sku']; + $defaults['quantity'] = $option['stock']; + $defaults['standardprice'] = number_format($option['price'] + $tax_added / 100 * $option['price'], 2, '.', ''); + $defaults['shippingweight'] = number_format($option['weight'], 2, '.', ''); + + if (!empty($option['image'])) { + $defaults['mainimage'] = HTTPS_CATALOG . 'image/' . $option['image']; + } + } + } + + if ($defaults['shippingweight'] <= 0) { + unset($defaults['shippingweight']); + unset($defaults['shippingweightunitofmeasure']); + } + + $filled_array = array(); + + foreach($fields_array as $field) { + + $value_array = array('value' => ''); + + if (isset($defaults[strtolower($field['name'])])) { + $value_array = array('value' => $defaults[strtolower($field['name'])]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + return $filled_array; + } + + private function fillSavedValues($product_id, $fields_array, $var = '') { + $this->load->model('extension/openbay/amazonus'); + $saved_listing = $this->model_extension_openbay_amazonus->getProduct($product_id, $var); + + $decoded_data = (array)json_decode($saved_listing['data']); + $saved_fields = (array)$decoded_data['fields']; + + $saved_fields['Quantity'] = $this->model_extension_openbay_amazonus->getProductQuantity($product_id, $var); + + $filled_array = array(); + + foreach($fields_array as $field) { + $value_array = array('value' => ''); + + if (isset($saved_fields[$field['name']])) { + $value_array = array('value' => $saved_fields[$field['name']]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + + return $filled_array; + } + + public function resetPending() { + $this->db->query("UPDATE `" . DB_PREFIX . "amazonus_product` SET `status` = 'saved' WHERE `status` = 'uploaded'"); + } + + private function validateForm() { + return true; + } + + private function formatUrlsInText($text) { + $regex_url = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; + preg_match_all($regex_url, $text, $matches); + $used_patterns = array(); + foreach($matches[0] as $pattern) { + if (!array_key_exists($pattern, $used_patterns)) { + $used_patterns[$pattern]=true; + $text = str_replace($pattern, "<a target='_blank' href=" . $pattern . ">" . $pattern . "</a>", $text); + } + } + return $text; + } +} diff --git a/public/admin/controller/extension/openbay/ebay.php b/public/admin/controller/extension/openbay/ebay.php new file mode 100644 index 0000000..b0687bf --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay.php @@ -0,0 +1,2421 @@ +<?php +class ControllerExtensionOpenbayEbay extends Controller { + public function install() { + $this->load->language('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/ebay_profile'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/ebay_profile'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/ebay_template'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/ebay_template'); + + $this->model_extension_openbay_ebay->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_ebay->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/ebay'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->ebay->validate(); + $data['links_settings'] = $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['links_itemlink'] = $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['links_subscribe'] = $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['links_usage'] = $this->url->link('extension/openbay/ebay/viewUsage', 'user_token=' . $this->session->data['user_token'], true); + $data['links_itemimport'] = $this->url->link('extension/openbay/ebay/viewItemImport', 'user_token=' . $this->session->data['user_token'], true); + $data['links_orderimport'] = $this->url->link('extension/openbay/ebay/viewOrderImport', 'user_token=' . $this->session->data['user_token'], true); + $data['links_usage'] = $this->url->link('extension/openbay/ebay/viewUsage', 'user_token=' . $this->session->data['user_token'], true); + $data['links_sync'] = $this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true); + $data['links_linkmaintenance'] = $this->url->link('extension/openbay/ebay/viewItemLinkMaintenance', 'user_token=' . $this->session->data['user_token'], true); + $data['links_summary'] = $this->url->link('extension/openbay/ebay/summary', 'user_token=' . $this->session->data['user_token'], true); + $data['links_profile'] = $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true); + $data['links_template'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/ebay/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=ebay'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/ebay_settings'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('localisation/currency'); + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('ebay', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/ebay/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=ebay'; + $data['link_token_renew'] = 'https://account.openbaypro.com/ebay/apiRenew/?utm_source=opencart_install&utm_medium=settings&utm_campaign=ebaytoken'; + $data['link_update'] = 'https://account.openbaypro.com/ebay/apiUpdate/?utm_source=opencart_install&utm_medium=settings&utm_campaign=ebayupdate'; + + if (isset($this->request->post['ebay_def_currency'])) { + $data['ebay_def_currency'] = $this->request->post['ebay_def_currency']; + } else { + $data['ebay_def_currency'] = $this->config->get('ebay_def_currency'); + } + $data['currency_list'] = $this->model_localisation_currency->getCurrencies(); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['ebay_status'])) { + $data['ebay_status'] = $this->request->post['ebay_status']; + } else { + $data['ebay_status'] = $this->config->get('ebay_status'); + } + + if (isset($this->request->post['ebay_token'])) { + $data['ebay_token'] = trim($this->request->post['ebay_token']); + } else { + $data['ebay_token'] = trim($this->config->get('ebay_token')); + } + + if (isset($this->request->post['ebay_secret'])) { + $data['ebay_secret'] = trim($this->request->post['ebay_secret']); + } else { + $data['ebay_secret'] = trim($this->config->get('ebay_secret')); + } + + if (isset($this->request->post['ebay_encryption_key'])) { + $data['ebay_encryption_key'] = trim($this->request->post['ebay_encryption_key']); + } else { + $data['ebay_encryption_key'] = trim($this->config->get('ebay_encryption_key')); + } + + if (isset($this->request->post['ebay_encryption_iv'])) { + $data['ebay_encryption_iv'] = trim($this->request->post['ebay_encryption_iv']); + } else { + $data['ebay_encryption_iv'] = trim($this->config->get('ebay_encryption_iv')); + } + + if (isset($this->request->post['ebay_enditems'])) { + $data['ebay_enditems'] = $this->request->post['ebay_enditems']; + } else { + $data['ebay_enditems'] = $this->config->get('ebay_enditems'); + } + + if (isset($this->request->post['ebay_relistitems'])) { + $data['ebay_relistitems'] = $this->request->post['ebay_relistitems']; + } else { + $data['ebay_relistitems'] = $this->config->get('ebay_relistitems'); + } + + if (isset($this->request->post['ebay_disable_nostock'])) { + $data['ebay_disable_nostock'] = $this->request->post['ebay_disable_nostock']; + } else { + $data['ebay_disable_nostock'] = $this->config->get('ebay_disable_nostock'); + } + if (isset($this->request->post['ebay_logging'])) { + $data['ebay_logging'] = $this->request->post['ebay_logging']; + } else { + $data['ebay_logging'] = $this->config->get('ebay_logging'); + } + + if (isset($this->request->post['ebay_created_hours'])) { + $data['ebay_created_hours'] = $this->request->post['ebay_created_hours']; + } else { + $data['ebay_created_hours'] = $this->config->get('ebay_created_hours'); + } + + if (isset($this->request->post['ebay_time_offset'])) { + $data['ebay_time_offset'] = $this->request->post['ebay_time_offset']; + } else { + $data['ebay_time_offset'] = $this->config->get('ebay_time_offset'); + } + + if (isset($this->request->post['ebay_update_notify'])) { + $data['ebay_update_notify'] = $this->request->post['ebay_update_notify']; + } else { + $data['ebay_update_notify'] = $this->config->get('ebay_update_notify'); + } + + if (isset($this->request->post['ebay_confirm_notify'])) { + $data['ebay_confirm_notify'] = $this->request->post['ebay_confirm_notify']; + } else { + $data['ebay_confirm_notify'] = $this->config->get('ebay_confirm_notify'); + } + + if (isset($this->request->post['ebay_confirmadmin_notify'])) { + $data['ebay_confirmadmin_notify'] = $this->request->post['ebay_confirmadmin_notify']; + } else { + $data['ebay_confirmadmin_notify'] = $this->config->get('ebay_confirmadmin_notify'); + } + + if (isset($this->request->post['ebay_itm_link'])) { + $data['ebay_itm_link'] = $this->request->post['ebay_itm_link']; + } else { + $data['ebay_itm_link'] = $this->config->get('ebay_itm_link'); + } + + if (isset($this->request->post['ebay_stock_allocate'])) { + $data['ebay_stock_allocate'] = $this->request->post['ebay_stock_allocate']; + } else { + $data['ebay_stock_allocate'] = $this->config->get('ebay_stock_allocate'); + } + + if (isset($this->request->post['ebay_create_date'])) { + $data['ebay_create_date'] = $this->request->post['ebay_create_date']; + } else { + $data['ebay_create_date'] = $this->config->get('ebay_create_date'); + } + + $data['durations'] = array( + 'Days_1' => $data['text_listing_1day'], + 'Days_3' => $data['text_listing_3day'], + 'Days_5' => $data['text_listing_5day'], + 'Days_7' => $data['text_listing_7day'], + 'Days_10' => $data['text_listing_10day'], + 'Days_30' => $data['text_listing_30day'], + 'GTC' => $data['text_listing_gtc'] + ); + + if (isset($this->request->post['ebay_duration'])) { + $data['ebay_duration'] = $this->request->post['ebay_duration']; + } else { + $data['ebay_duration'] = $this->config->get('ebay_duration'); + } + + if (isset($this->request->post['ebay_measurement'])) { + $data['ebay_measurement'] = $this->request->post['ebay_measurement']; + } else { + $data['ebay_measurement'] = $this->config->get('ebay_measurement'); + } + + if (isset($this->request->post['ebay_default_addressformat'])) { + $data['ebay_default_addressformat'] = $this->request->post['ebay_default_addressformat']; + } else { + $data['ebay_default_addressformat'] = $this->config->get('ebay_default_addressformat'); + } + + $data['payment_options'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + + if (isset($this->request->post['ebay_payment_types'])) { + $data['ebay_payment_types'] = $this->request->post['ebay_payment_types']; + } else { + $data['ebay_payment_types'] = $this->config->get('ebay_payment_types'); + } + + if (isset($this->request->post['ebay_payment_instruction'])) { + $data['ebay_payment_instruction'] = $this->request->post['ebay_payment_instruction']; + } else { + $data['ebay_payment_instruction'] = $this->config->get('ebay_payment_instruction'); + } + + if (isset($this->request->post['ebay_payment_paypal_address'])) { + $data['ebay_payment_paypal_address'] = $this->request->post['ebay_payment_paypal_address']; + } else { + $data['ebay_payment_paypal_address'] = $this->config->get('ebay_payment_paypal_address'); + } + + if (isset($this->request->post['ebay_payment_immediate'])) { + $data['ebay_payment_immediate'] = $this->request->post['ebay_payment_immediate']; + } else { + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + } + + if (isset($this->request->post['ebay_tax_listing'])) { + $data['ebay_tax_listing'] = $this->request->post['ebay_tax_listing']; + } else { + $data['ebay_tax_listing'] = $this->config->get('ebay_tax_listing'); + } + + if (isset($this->request->post['ebay_tax'])) { + $data['ebay_tax'] = $this->request->post['ebay_tax']; + } else { + $data['ebay_tax'] = $this->config->get('ebay_tax'); + } + + if (isset($this->request->post['ebay_import_unpaid'])) { + $data['ebay_import_unpaid'] = $this->request->post['ebay_import_unpaid']; + } else { + $data['ebay_import_unpaid'] = $this->config->get('ebay_import_unpaid'); + } + + if (isset($this->request->post['ebay_status_partial_refund_id'])) { + $data['ebay_status_partial_refund_id'] = $this->request->post['ebay_status_partial_refund_id']; + } else { + $data['ebay_status_partial_refund_id'] = $this->config->get('ebay_status_partial_refund_id'); + } + + if (isset($this->request->post['ebay_status_import_id'])) { + $data['ebay_status_import_id'] = $this->request->post['ebay_status_import_id']; + } else { + $data['ebay_status_import_id'] = $this->config->get('ebay_status_import_id'); + } + + if (isset($this->request->post['ebay_status_paid_id'])) { + $data['ebay_status_paid_id'] = $this->request->post['ebay_status_paid_id']; + } else { + $data['ebay_status_paid_id'] = $this->config->get('ebay_status_paid_id'); + } + + if (isset($this->request->post['ebay_status_shipped_id'])) { + $data['ebay_status_shipped_id'] = $this->request->post['ebay_status_shipped_id']; + } else { + $data['ebay_status_shipped_id'] = $this->config->get('ebay_status_shipped_id'); + } + + if (isset($this->request->post['ebay_status_cancelled_id'])) { + $data['ebay_status_cancelled_id'] = $this->request->post['ebay_status_cancelled_id']; + } else { + $data['ebay_status_cancelled_id'] = $this->config->get('ebay_status_cancelled_id'); + } + + if (isset($this->request->post['ebay_status_refunded_id'])) { + $data['ebay_status_refunded_id'] = $this->request->post['ebay_status_refunded_id']; + } else { + $data['ebay_status_refunded_id'] = $this->config->get('ebay_status_refunded_id'); + } + + $data['api_server'] = $this->openbay->ebay->getServer(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_settings', $data)); + } + + public function updateSettings() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateSettings(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function updateCategories() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateCategories(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function updateStore() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateStore(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getCategories() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getCategory($this->request->get['parent']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getSuggestedCategories() { + $this->load->model('extension/openbay/ebay'); + + $this->load->language('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getSuggestedCategories($this->request->get['qry']); + + if (empty($json['data'])) { + $json['msg'] = $this->language->get('error_category_nosuggestions'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getShippingService() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getShippingService($this->request->get['loc'], $this->request->get['type']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getEbayCategorySpecifics() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('catalog/product'); + $this->load->model('catalog/attribute'); + + $response = $this->model_extension_openbay_ebay->getEbayCategorySpecifics($this->request->get['category_id']); + + $recommendation_data = array(); + + if (isset($response['data']['Recommendations']['NameRecommendation'])) { + if (isset($response['data']['Recommendations']['NameRecommendation']['Name'])) { + $recommendations = array($response['data']['Recommendations']['NameRecommendation']); + } else { + $recommendations = $response['data']['Recommendations']['NameRecommendation']; + } + + foreach ($recommendations as $name_recommendation_key => $name_recommendation) { + $recommendation_data_option = array( + 'name' => $name_recommendation['Name'], + 'validation' => + array( + 'max_values' => $name_recommendation['ValidationRules']['MaxValues'], + 'selection_mode' => $name_recommendation['ValidationRules']['SelectionMode'], + ), + 'unmatched_value' => '', + ); + + if (isset($name_recommendation['ValueRecommendation'])) { + if (!isset($name_recommendation['ValueRecommendation']['Value'])) { + foreach($name_recommendation['ValueRecommendation'] as $value_recommendation_key => $value_recommendation) { + $recommendation_data_option['options'][] = $value_recommendation['Value']; + } + } + } + + $recommendation_data[] = $recommendation_data_option; + } + + if (isset($this->request->get['product_id'])) { + $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); + + foreach ($product_attributes as $product_attribute) { + $attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']); + + if ($attribute_info) { + // search the ebay attribute results for a match + foreach($recommendation_data as $name_recommendation_key => $name_recommendation) { + if (strtolower($attribute_info['name']) == strtolower($name_recommendation['name'])) { + $preset_match_found = false; + + if (isset($name_recommendation['options'])) { + foreach($name_recommendation['options'] as $value_recommendation_key => $value_recommendation) { + if (strtolower($value_recommendation) == strtolower($product_attribute['product_attribute_description'][$this->config->get('config_language_id')]['text'])) { + $preset_match_found = $value_recommendation_key; + } + } + } + + if ($preset_match_found === false) { + if ($name_recommendation['validation']['selection_mode'] == 'FreeText') { + $recommendation_data[$name_recommendation_key]['unmatched_value'] = $product_attribute['product_attribute_description'][$this->config->get('config_language_id')]['text']; + } + } else { + $recommendation_data[$name_recommendation_key]['matched_value_key'] = $preset_match_found; + } + } + } + } + } + } + } + + $json = array( + 'data' => $recommendation_data, + 'msg' => $response['msg'], + 'error' => $response['error'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getCategoryFeatures() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getCategoryFeatures($this->request->get['category']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function searchEbayCatalog() { + $this->load->language('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_product'); + + $response = $this->model_extension_openbay_ebay_product->searchEbayCatalog($this->request->post['search'], $this->request->post['category_id']); + + $json = array('error' => false, 'error_message' => ''); + + if (isset($response['ack'])) { + if ($response['ack'] == 'Success') { + $json['results'] = (int)$response['productSearchResult']['paginationOutput']['totalEntries']; + $json['page'] = (int)$response['productSearchResult']['paginationOutput']['pageNumber']; + $json['page_total'] = (int)$response['productSearchResult']['paginationOutput']['totalPages']; + + if (isset($response['productSearchResult']['products'])) { + $json['products'] = $response['productSearchResult']['products']; + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_no_products')); + } + } else { + if (isset($response['errorMessage']['error']['message'])) { + $json = array('error' => true, 'error_message' => $response['errorMessage']['error']['message']); + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_loading_catalog')); + } + } + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_generic_fail')); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function summary() { + $this->load->language('extension/openbay/ebay_summary'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/summary', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_summary', $data)); + } + + public function getSellerSummary() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getSellerSummary(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function verifyCredentials() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->verifyCredentials(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function viewItemImport() { + $this->load->language('extension/openbay/ebay_import'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_product'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewItemImport', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + $data['maintenance'] = $this->config->get('config_maintenance'); + $data['image_import'] = $this->model_extension_openbay_ebay_product->countImportImages(); + $data['ini_setting_post_max_size'] = ini_get('post_max_size'); + $data['ini_setting_memory_limit'] = ini_get('memory_limit'); + $data['image_import_link'] = $this->url->link('extension/openbay/ebay/getImportImages', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_item_import', $data)); + } + + public function importItems() { + $data = array( + 'adv' => $this->request->get['advanced'], + 'c' => 1, + 'd' => $this->request->get['desc'], + 'n' => $this->request->get['note'], + 'cat' => $this->request->get['categories'], + ); + + $this->openbay->ebay->callNoResponse('setup/getItemsMain/', $data); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getImportImages() { + set_time_limit(0); + $this->openbay->ebay->getImages(); + + $json = array('error' => false, 'msg' => 'OK'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function importOrdersManual() { + $this->openbay->ebay->callNoResponse('order/getOrdersManual/'); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getProductStock() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getProductStock($this->request->get['pid']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function setProductStock() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('catalog/product'); + + $product = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $json = array(); + + if ($product['subtract'] == 1) { + $this->openbay->ebay->productUpdateListen($this->request->get['product_id']); + + $json['error'] = false; + $json['msg'] = 'ok'; + } else { + $this->load->language('extension/openbay/ebay_links'); + + $json['error'] = true; + $json['msg'] = $this->language->get('error_subtract_setting'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPlans() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getPlans(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getMyPlan() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getMyPlan(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function subscription() { + $this->load->language('extension/openbay/ebay_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + $data['obp_token'] = $this->config->get('ebay_token'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_subscription', $data)); + } + + public function viewUsage() { + $this->load->language('extension/openbay/ebay_usage'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/view_usage', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + $data['obp_token'] = $this->config->get('ebay_token'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_usage', $data)); + } + + public function getUsage() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getUsage(); + $json['html'] = base64_decode($json['html']); + $json['lasterror'] = $this->openbay->ebay->lasterror; + $json['lastmsg'] = $this->openbay->ebay->lastmsg; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function viewOrderImport() { + $this->load->language('extension/openbay/ebay_orders'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewOrderImport', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_order_import', $data)); + } + + public function syncronise() { + $this->load->language('extension/openbay/ebay_syncronise'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['warning'])) { + $data['error_warning'] = $this->session->data['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_syncronise', $data)); + } + + public function viewItemLinks() { + $this->load->language('extension/openbay/ebay_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/ebay'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['edit_url'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=', true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $total_linked = $this->model_extension_openbay_ebay->totalLinked(); + + if (isset($this->request->get['linked_item_page'])){ + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 100; + } + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = 100; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['linked_items'] = $this->model_extension_openbay_ebay->loadLinked($linked_item_limit, $linked_item_page); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_item_link', $data)); + } + + public function saveItemLink() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->saveItemLink($this->request->get); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeItemLink() { + $this->load->language('extension/openbay/ebay'); + + $this->openbay->ebay->removeItemByProductId($this->request->get['product_id']); + + $json = array('error' => false, 'msg' => $this->language->get('item_link_removed')); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function loadUnlinked(){ + set_time_limit(0); + + $this->load->model('extension/openbay/ebay'); + + $filter = array(); + + if (isset($this->request->post['filter_variant']) && !empty($this->request->post['filter_variant'])) { + $filter['variants'] = (int)$this->request->post['filter_variant']; + } + + if (isset($this->request->post['filter_title']) && !empty($this->request->post['filter_title'])) { + $filter['title'] = (string)$this->request->post['filter_title']; + } + + if (isset($this->request->post['filter_qty_min']) && !empty($this->request->post['filter_qty_min'])) { + $filter['qty_min'] = (int)$this->request->post['filter_qty_min']; + } + + if (isset($this->request->post['filter_qty_max']) && !empty($this->request->post['filter_qty_max'])) { + $filter['qty_max'] = (int)$this->request->post['filter_qty_max']; + } + + $data = $this->model_extension_openbay_ebay->loadUnlinked(200, $this->request->get['page'], $filter); + + if (!empty($data)) { + $data['more_pages'] = 1; + + if ($data['next_page'] > $data['max_page']){ + $data['more_pages'] = 0; + } + + $json['data'] = $data; + } else { + $json['data'] = null; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function loadLinkedStatus(){ + set_time_limit(0); + + $this->load->model('extension/openbay/ebay'); + + $json['data'] = ''; + if (isset($this->request->post['item_id']) && !empty($this->request->post['item_id'])){ + $data = $this->model_extension_openbay_ebay->loadLinkedStatus($this->request->post['item_id']); + + if (!empty($data)) { + $json['data'] = $data; + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + private function checkConfig() { + if ($this->config->get('ebay_token') == '' || $this->config->get('ebay_secret') == '') { + return false; + } else { + return true; + } + } + + public function edit() { + if ($this->checkConfig() == true) { + if (!empty($this->request->get['product_id'])) { + $this->load->language('extension/openbay/ebay_edit'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_product'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['view_link'] = $this->config->get('ebay_itm_link') . $this->openbay->ebay->getEbayItemId($this->request->get['product_id']); + $data['user_token'] = $this->session->data['user_token']; + $data['product_id'] = $this->request->get['product_id']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_edit', $data)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } + + public function editLoad() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/ebay_product'); + $this->load->model('tool/image'); + + $item_id = $this->openbay->ebay->getEbayItemId($this->request->get['product_id']); + + if (!empty($item_id)) { + $listings = $this->openbay->ebay->getEbayListing($item_id); + $stock = $this->openbay->ebay->getProductStockLevel($this->request->get['product_id']); + $reserve = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id); + $options = array(); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $this->load->model('extension/module/openstock'); + $data['addon']['openstock'] = true; + $product_info['options'] = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + $product_info['option_groups'] = $this->model_extension_openbay_ebay_product->getProductOptions($this->request->get['product_id']); + + $t = array(); + $t_rel = array(); + + foreach($product_info['option_groups'] as $group) { + $t_tmp = array(); + + foreach($group['product_option_value'] as $group_node) { + $t_tmp[$group_node['option_value_id']] = $group_node['name']; + $t_rel[$group_node['product_option_value_id']] = $group['name']; + } + + $t[] = array('name' => $group['name'], 'child' => $t_tmp); + } + + if (!isset($listings['variations']['Variation'][1])) { + $listings['variations']['Variation'] = array($listings['variations']['Variation']); + } + + foreach($product_info['options'] as $option) { + $option['base64'] = base64_encode(serialize($option['option_values'])); + $option_reserve = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id, $option['sku']); + if ($option_reserve == false) { + $option['reserve'] = 0; + } else { + $option['reserve'] = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id, $option['sku']); + } + + $ebay_listing = ''; + + foreach($listings['variations']['Variation'] as $listing) { + + $sku = (isset($listing['SKU']) ? $listing['SKU'] : ''); + + if ($sku != '' && $sku == $option['sku']) { + $listing['StartPrice'] = number_format($listing['StartPrice'], 2, '.', ''); + $listing['Quantity'] = $listing['Quantity'] - $listing['SellingStatus']['QuantitySold']; + + $ebay_listing = $listing; + } + } + + $options[] = array('ebay' => $ebay_listing, 'local' => $option, 'sku' => $option['sku'], 'product_option_variant_id' => $option['product_option_variant_id']); + } + + //unset variants that dont appear on eBay + $options_inactive = array(); + foreach($options as $k => $option) { + if (empty($option['ebay'])) { + $options_inactive[] = $options[$k]; + unset($options[$k]); + } + } + + $variant = array( + 'variant' => 1, + 'data' => array( + 'group_information' => array( + 'option_groups' => base64_encode(serialize($t)), + 'option_group_relationship' => base64_encode(serialize($t_rel)), + ), + 'options' => $options, + 'options_inactive' => $options_inactive + ) + ); + + } else { + $variant = array('variant' => 0, 'data' => ''); + } + + if ($reserve == false) { + $reserve = 0; + } + + $data = array( + 'listing' => $listings, + 'stock' => $stock, + 'reserve' => $reserve, + 'variant' => $variant, + 'product' => $product_info + ); + + if (!empty($listings)) { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false, 'data' => $data))); + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true))); + } + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true))); + } + } + + public function editSave() { + if ($this->checkConfig() == true && $this->request->server['REQUEST_METHOD'] == 'POST') { + + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->editSave($this->request->post); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function create() { + if ($this->checkConfig() == true) { + if (!empty($this->request->get['product_id'])) { + $this->load->language('extension/openbay/ebay_new'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('extension/openbay/ebay_product'); + $this->load->model('extension/openbay/ebay_profile'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $setting = array(); + + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + $setting['package_type'] = $this->openbay->ebay->getSetting('package_type'); + $setting['shipping_types'] = $this->openbay->ebay->getSetting('shipping_types'); + $setting['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + $setting['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + $setting['product_details'] = $this->openbay->ebay->getSetting('product_details'); + $setting['listing_restrictions'] = $this->openbay->ebay->getSetting('listing_restrictions'); + + if (!isset($setting['product_details']['product_identifier_unavailable_text'])) { + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&user_token=' . $this->session->data['user_token'], true)); + } + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $data['setting'] = $setting; + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $this->load->model('extension/module/openstock'); + $data['addon']['openstock'] = true; + $product_info['options'] = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + + $product_info['options_array'] = base64_encode(serialize($product_info['options'][0]['option_values'])); + + $product_info['option_groups'] = $this->model_extension_openbay_ebay_product->getProductOptions($this->request->get['product_id']); + + $option_group_array = array(); + $option_group_relation_array = array(); + + foreach($product_info['option_groups'] as $option_group) { + $child_option = array(); + + foreach($option_group['product_option_value'] as $group_node) { + $child_option[$group_node['option_value_id']] = $group_node['name']; + $option_group_relation_array[$group_node['product_option_value_id']] = $option_group['name']; + } + + $option_group_array[] = array('name' => $option_group['name'], 'child' => $child_option); + } + + $product_info['option_group_array'] = base64_encode(serialize($option_group_array)); + $product_info['option_group_relation_array'] = base64_encode(serialize($option_group_relation_array)); + } + + // get the product tax rate from opencart + if (isset($product_info['tax_class_id'])) { + $product_info['defaults']['tax'] = $this->model_extension_openbay_ebay_product->getTaxRate($product_info['tax_class_id']); + } else { + $product_info['defaults']['tax'] = 0.00; + } + + //get the popular categories the user has used + $product_info['popular_cats'] = $this->model_extension_openbay_ebay->getPopularCategories(); + + //get shipping profiles + $product_info['profiles_shipping'] = $this->model_extension_openbay_ebay_profile->getAll(0); + //get default shipping profile + $product_info['profiles_shipping_def'] = $this->model_extension_openbay_ebay_profile->getDefault(0); + + //get returns profiles + $product_info['profiles_returns'] = $this->model_extension_openbay_ebay_profile->getAll(1); + //get default returns profile + $product_info['profiles_returns_def'] = $this->model_extension_openbay_ebay_profile->getDefault(1); + $data['data']['shipping_international_zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + //get theme profiles + $product_info['profiles_theme'] = $this->model_extension_openbay_ebay_profile->getAll(2); + //get default returns profile + $product_info['profiles_theme_def'] = $this->model_extension_openbay_ebay_profile->getDefault(2); + + //get generic profiles + $product_info['profiles_generic'] = $this->model_extension_openbay_ebay_profile->getAll(3); + //get default generic profile + $product_info['profiles_generic_def'] = $this->model_extension_openbay_ebay_profile->getDefault(3); + + //product attributes - this is just a direct pass through used with the template tag + $product_info['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($this->request->get['product_id']))); + + //post edit link + $product_info['edit_link'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true); + + //images + $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $img_info = getimagesize(DIR_IMAGE . $product_info['image']); + + $product_info['product_images'][] = array( + 'image' => $product_info['image'], + 'preview' => $this->model_tool_image->resize($product_info['image'], 100, 100), + 'full' => HTTPS_CATALOG . 'image/' . $product_info['image'], + 'width' => $img_info[0], + 'height' => $img_info[1], + ); + } + + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $img_info = getimagesize(DIR_IMAGE . $product_image['image']); + + $product_info['product_images'][] = array( + 'image' => $product_image['image'], + 'preview' => $this->model_tool_image->resize($product_image['image'], 100, 100), + 'full' => HTTPS_CATALOG . 'image/' . $product_image['image'], + 'width' => $img_info[0], + 'height' => $img_info[1], + ); + } + } + + $product_info['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers(); + $product_info['payments'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + $product_info['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $product_info['store_cats'] = $this->model_extension_openbay_ebay->getSellerStoreCategories(); + + $product_info['defaults']['cod_surcharge'] = 0; + + foreach($product_info['payments'] as $payment) { + if ($payment['ebay_name'] == 'COD') { + $product_info['defaults']['cod_surcharge'] = 1; + } + } + + $product_info['defaults']['ebay_payment_types'] = $this->config->get('ebay_payment_types'); + $product_info['defaults']['paypal_address'] = $this->config->get('ebay_payment_paypal_address'); + $product_info['defaults']['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + $product_info['defaults']['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + + $product_info['defaults']['gallery_height'] = '400'; + $product_info['defaults']['gallery_width'] = '400'; + $product_info['defaults']['thumb_height'] = '100'; + $product_info['defaults']['thumb_width'] = '100'; + + $product_info['defaults']['ebay_measurement'] = $this->config->get('ebay_measurement'); + + $product_info['defaults']['listing_duration'] = $this->config->get('ebay_duration'); + if ($product_info['defaults']['listing_duration'] == '') { + $product_info['defaults']['listing_duration'] = 'Days_30'; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if ($product_info['quantity'] < 1 && (!isset($product_info['has_option']) || $product_info['has_option'] == 0)) { + $data['error_warning'] = $this->language->get('error_no_stock'); + } + + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $weight_parts = explode('.', $product_info['weight']); + $product_info['weight_major'] = (int)$weight_parts[0]; + $product_info['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + + $data['product'] = $product_info; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_new', $data)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } + + public function createBulk() { + if ($this->checkConfig() == true) { + if (!empty($this->request->post['selected'])) { + $this->load->language('extension/openbay/ebay_newbulk'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_profile'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/createBulk', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['error_warning'] = array(); + + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['image_directory'] = DIR_IMAGE; + + $active_list = $this->model_extension_openbay_ebay->getLiveListingArray(); + + $products = array(); + + if ($this->openbay->addonLoad('openstock')) { + $openstock = 1; + } else { + $openstock = 0; + } + + foreach ($this->request->post['selected'] as $product_id) { + if (!array_key_exists($product_id, $active_list)) { + + $prod = $this->model_catalog_product->getProduct($product_id); + + if ($openstock == 1 && isset($prod['has_option']) && $prod['has_option'] == 1) { + $data['error_warning']['os'] = $this->language->get('text_error_variants'); + } else { + if ($prod['quantity'] > 0) { + if ($prod['image'] && file_exists(DIR_IMAGE . $prod['image'])) { + $prod['image'] = $this->model_tool_image->resize($prod['image'], 80, 80); + } else { + $prod['image'] = $this->model_tool_image->resize('no_image.png', 80, 80); + } + + $products[] = $prod; + } else { + $data['error_warning']['stock'] = $this->language->get('text_error_stock'); + } + } + } else { + $data['error_warning']['exists'] = $this->language->get('text_exists'); + } + } + + $data['count'] = count($products); + $data['user_token'] = $this->session->data['user_token']; + $data['listing_link'] = $this->config->get('ebay_itm_link'); + + $plan = $this->model_extension_openbay_ebay->getMyPlan(); + + if ($plan['plan']['listing_bulk'] == 1) { + if ($data['count'] == 0) { + $data['error_fail'][] = $this->language->get('text_error_no_product'); + } else { + if (($plan['plan']['listing_limit'] == 0) || (($plan['usage']['items'] + $data['count']) <= $plan['plan']['listing_limit'])) { + if ($data['count'] > 5) { + $data['error_warning']['count'] = sprintf($this->language->get('text_error_count'), $data['count']); + } + + //load the settings from eBay + $setting = array(); + + $setting['product_details'] = $this->openbay->ebay->getSetting('product_details'); + + if (!isset($setting['product_details']['product_identifier_unavailable_text'])) { + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $data['setting'] = $setting; + + //get generic profiles + $product_info['profiles_generic'] = $this->model_extension_openbay_ebay_profile->getAll(3); + //get default generic profile + $product_info['profiles_generic_def'] = $this->model_extension_openbay_ebay_profile->getDefault(3); + if ($product_info['profiles_generic_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_generic_profile'); + } + + //get shipping profiles + $product_info['profiles_shipping'] = $this->model_extension_openbay_ebay_profile->getAll(0); + //get default shipping profile + $product_info['profiles_shipping_def'] = $this->model_extension_openbay_ebay_profile->getDefault(0); + //check it has a default profile + if ($product_info['profiles_shipping_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_ship_profile'); + } + + //get returns profiles + $product_info['profiles_returns'] = $this->model_extension_openbay_ebay_profile->getAll(1); + //get default returns profile + $product_info['profiles_returns_def'] = $this->model_extension_openbay_ebay_profile->getDefault(1); + //check it has a default profile + if ($product_info['profiles_returns_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_return_profile'); + } + + //get returns profiles + $product_info['profiles_theme'] = $this->model_extension_openbay_ebay_profile->getAll(2); + //get default returns profile + $product_info['profiles_theme_def'] = $this->model_extension_openbay_ebay_profile->getDefault(2); + //check it has a default profile + if ($product_info['profiles_theme_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_theme_profile'); + } + + // get the product tax rate + if (isset($product_info['tax_class_id'])) { + $product_info['defaults']['tax'] = $this->model_extension_openbay_ebay_product->getTaxRate($product_info['tax_class_id']); + } else { + $product_info['defaults']['tax'] = 0.00; + } + + $data['products'] = $products; + + $product_info['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers(); + $product_info['payments'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + $product_info['store_cats'] = $this->model_extension_openbay_ebay->getSellerStoreCategories(); + + $product_info['defaults']['ebay_template'] = $this->config->get('ebay_template'); + + $product_info['defaults']['listing_duration'] = $this->config->get('ebay_duration'); + if ($product_info['defaults']['listing_duration'] == '') { + $product_info['defaults']['listing_duration'] = 'Days_30'; + } + + $data['default'] = $product_info; + } else { + $data['error_fail']['plan'] = sprintf($this->language->get('text_item_limit'), $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } else { + $data['error_fail']['plan'] = sprintf($this->language->get('text_bulk_plan_error'), $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_new_bulk', $data)); + } else { + $this->load->language('extension/openbay/ebay_newbulk'); + $this->session->data['warning'] = $this->language->get('text_error_no_selection'); + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + } + + public function verify() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $this->model_extension_openbay_ebay->logCategoryUsed($this->request->post['finalCat']); + + $item_id = $this->openbay->ebay->getEbayItemId($this->request->post['product_id']); + + if ($item_id == false) { + $data = $this->request->post; + + if ($data['template'] != 'None') { + $template = $this->model_extension_openbay_ebay_template->get($data['template']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + } else { + $data['template_html'] = ''; + } + + // set shipping data + $data['national'] = $data['data']['national']; + $data['international'] = $data['data']['international']; + unset($data['data']); + + if (!empty($data['img_tpl'])) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + $this->load->model('tool/image'); + + foreach ($data['img_tpl'] as $k => $v) { + $tmp_gallery_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['gallery_width'], $data['gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['thumb_width'], $data['thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$data['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + if (!empty($data['product_info']['sku'])){ + $data['sku'] = $data['product_info']['sku']; + } + + $json = $this->model_extension_openbay_ebay->ebayVerifyAddItem($data, $this->request->get['options']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true, 'msg' => 'This item is already listed in your eBay account', 'item' => $item_id))); + } + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function verifyBulk() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $post = $this->request->post; + $data = array(); + + //load all of the listing defaults and assign to correct variable names + $profile_shipping = $this->model_extension_openbay_ebay_profile->get($post['shipping_profile']); + $profile_return = $this->model_extension_openbay_ebay_profile->get($post['return_profile']); + $profile_template = $this->model_extension_openbay_ebay_profile->get($post['theme_profile']); + $profile_generic = $this->model_extension_openbay_ebay_profile->get($post['generic_profile']); + + $payments = $this->model_extension_openbay_ebay->getPaymentTypes(); + $payments_accepted = $this->config->get('ebay_payment_types'); + $product_info = $this->model_catalog_product->getProduct($post['product_id']); + + // set shipping data + $data['national'] = $profile_shipping['data']['national']; + $data['international'] = $profile_shipping['data']['international']; + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$post['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + + $data['description'] = $product_info['description']; + $data['name'] = $post['title']; + $data['sub_name'] = ''; + $data['bestoffer'] = 0; + $data['finalCat'] = $post['finalCat']; + $data['price'][0] = $post['price']; + $data['qty'][0] = (int)$post['qty']; + $data['product_id'] = (int)$post['product_id']; + + $data['feat'] = $post['feat']; + $data['featother'] = $post['featother']; + + if (!empty($product_info['sku'])){ + $data['sku'] = $product_info['sku']; + } + + if (isset($post['identifier_ean']) && !empty($post['identifier_ean'])){ + $data['identifier_ean'] = $post['identifier_ean']; + } + + if (isset($post['identifier_isbn']) && !empty($post['identifier_isbn'])){ + $data['identifier_isbn'] = $post['identifier_isbn']; + } + + if (isset($post['identifier_upc']) && !empty($post['identifier_upc'])){ + $data['identifier_upc'] = $post['identifier_upc']; + } + + $data['auction_duration'] = $post['duration']; + $data['condition'] = (isset($post['condition']) && $post['condition'] != 0 ? $post['condition'] : ''); + $data['auction_type'] = 'FixedPriceItem'; + $data['catalog_epid'] = (isset($post['catalog_epid']) && $post['catalog_epid'] != 0 ? $post['catalog_epid'] : ''); + $data['identifier_upc'] = (isset($post['identifier_upc']) && $post['identifier_upc'] != '' ? $post['identifier_upc'] : ''); + $data['identifier_isbn'] = (isset($post['identifier_isbn']) && $post['identifier_isbn'] != '' ? $post['identifier_isbn'] : ''); + $data['identifier_ean'] = (isset($post['identifier_ean']) && $post['identifier_ean'] != '' ? $post['identifier_ean'] : ''); + + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + $data['paypal_email'] = $this->config->get('ebay_payment_paypal_address'); + $data['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + + if (isset($profile_return['data']['returns_accepted'])) { + $data['returns_accepted'] = $profile_return['data']['returns_accepted']; + } + if (isset($profile_return['data']['returns_policy'])) { + $data['return_policy'] = $profile_return['data']['returns_policy']; + } + if (isset($profile_return['data']['returns_option'])) { + $data['returns_option'] = $profile_return['data']['returns_option']; + } + if (isset($profile_return['data']['returns_within'])) { + $data['returns_within'] = $profile_return['data']['returns_within']; + } + if (isset($profile_return['data']['returns_shipping'])) { + $data['returns_shipping'] = $profile_return['data']['returns_shipping']; + } + if (isset($profile_return['data']['returns_restocking_fee'])) { + $data['returns_restocking_fee'] = $profile_return['data']['returns_restocking_fee']; + } + + $data['location'] = $profile_shipping['data']['location']; + $data['postcode'] = $profile_shipping['data']['postcode']; + $data['dispatch_time'] = $profile_shipping['data']['dispatch_time']; + + if (isset($profile_shipping['data']['country'])) { + $data['country'] = $profile_shipping['data']['country']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_dropoff'])) { + $data['eligible_for_pickup_dropoff'] = $profile_shipping['data']['eligible_for_pickup_dropoff']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_instore'])) { + $data['eligible_for_pickup_instore'] = $profile_shipping['data']['eligible_for_pickup_instore']; + } + + if (isset($profile_shipping['data']['global_shipping'])) { + $data['global_shipping'] = $profile_shipping['data']['global_shipping']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount'])) { + $data['promotional_shipping_discount'] = $profile_shipping['data']['promotional_shipping_discount']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount_international'])) { + $data['promotional_shipping_discount_international'] = $profile_shipping['data']['promotional_shipping_discount_international']; + } + + $data['get_it_fast'] = (isset($profile_shipping['data']['get_it_fast']) ? $profile_shipping['data']['get_it_fast'] : 0); + + if (isset($profile_template['data']['ebay_template_id'])) { + $template = $this->model_extension_openbay_ebay_template->get($profile_template['data']['ebay_template_id']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + $data['template'] = $profile_template['data']['ebay_template_id']; + } else { + $data['template_html'] = ''; + $data['template'] = ''; + } + + $data['gallery_plus'] = $profile_template['data']['ebay_gallery_plus']; + $data['gallery_super'] = $profile_template['data']['ebay_supersize']; + + $data['private_listing'] = $profile_generic['data']['private_listing']; + + //product attributes - this is just a direct pass through used with the template tag + $data['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($post['product_id']))); + + $data['payments'] = array(); + foreach($payments as $payment) { + if ($payments_accepted[$payment['ebay_name']] == 1) { + $data['payments'][$payment['ebay_name']] = 1; + } + } + + $data['main_image'] = 0; + $data['img'] = array(); + + $product_images = $this->model_catalog_product->getProductImages($post['product_id']); + + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $data['img'][] = $product_info['image']; + } + + if (isset($profile_template['data']['ebay_img_ebay']) && $profile_template['data']['ebay_img_ebay'] == 1) { + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $data['img'][] = $product_image['image']; + } + } + } + + if (isset($profile_template['data']['ebay_img_template']) && $profile_template['data']['ebay_img_template'] == 1) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + + //if the user has not set the exclude default image, add it to the array for theme images. + $key_offset = 0; + if (!isset($profile_template['data']['default_img_exclude']) || $profile_template['data']['default_img_exclude'] != 1) { + $tmp_gallery_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + $key_offset = 1; + } + + //loop through the product images and add them. + foreach ($product_images as $k => $v) { + $tmp_gallery_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $weight_parts = explode('.', $product_info['weight']); + + // package size and weights + $data['package']['depth'] = $product_info['height']; + $data['package']['irregular'] = 0; + $data['package']['length'] = $product_info['length']; + $data['package']['unit'] = $this->config->get('ebay_measurement'); + $data['package']['weight_major'] = (int)$weight_parts[0]; + $data['package']['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + $data['package']['width'] = $product_info['width']; + + $package_types = $this->openbay->ebay->getSetting('package_type'); + + foreach ($package_types as $package_type) { + if ($package_type['default'] == 1) { + $data['package']['package'] = $package_type['code']; + } + } + + $data = array_merge($data, $profile_shipping['data']); + + $verify_response = $this->model_extension_openbay_ebay->ebayVerifyAddItem($data, 'no'); + + $json = array( + 'errors' => $verify_response['data']['Errors'], + 'fees' => $verify_response['data']['Fees'], + 'itemid' => (string)$verify_response['data']['ItemID'], + 'preview' => (string)$verify_response['data']['link'], + 'i' => $this->request->get['i'], + 'ack' => (string)$verify_response['data']['Ack'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function listItem() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('catalog/filter'); + + if ($this->checkConfig() == true && $this->request->server['REQUEST_METHOD'] == 'POST') { + $data = $this->request->post; + + if ($data['template'] != 'None') { + $template = $this->model_extension_openbay_ebay_template->get($data['template']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + } else { + $data['template_html'] = ''; + } + + // set shipping data + $data['national'] = $data['data']['national']; + $data['international'] = $data['data']['international']; + unset($data['data']); + + if (!empty($data['img_tpl'])) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + $this->load->model('tool/image'); + + foreach ($data['img_tpl'] as $k => $v) { + $tmp_gallery_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['gallery_width'], $data['gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['thumb_width'], $data['thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$data['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + if (!empty($data['product_info']['sku'])){ + $data['sku'] = $data['product_info']['sku']; + } + + $json = $this->model_extension_openbay_ebay->ebayAddItem($data, $this->request->get['options']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function listItemBulk() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $post = $this->request->post; + $data = array(); + + //load all of the listing defaults and assign to correct variable names + $profile_shipping = $this->model_extension_openbay_ebay_profile->get($post['shipping_profile']); + $profile_return = $this->model_extension_openbay_ebay_profile->get($post['return_profile']); + $profile_template = $this->model_extension_openbay_ebay_profile->get($post['theme_profile']); + $profile_generic = $this->model_extension_openbay_ebay_profile->get($post['generic_profile']); + $payments = $this->model_extension_openbay_ebay->getPaymentTypes(); + $payments_accepted = $this->config->get('ebay_payment_types'); + $product_info = $this->model_catalog_product->getProduct($post['product_id']); + + // set shipping data + $data['national'] = $profile_shipping['data']['national']; + $data['international'] = $profile_shipping['data']['international']; + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$post['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + $data['description'] = $product_info['description']; + $data['name'] = $post['title']; + $data['sub_name'] = ''; + $data['bestoffer'] = 0; + $data['finalCat'] = $post['finalCat']; + $data['price'][0] = $post['price']; + $data['qty'][0] = $post['qty']; + $data['product_id'] = $post['product_id']; + + $data['feat'] = $post['feat']; + $data['featother'] = $post['featother']; + + if (!empty($product_info['sku'])){ + $data['sku'] = $product_info['sku']; + } + + if (isset($post['identifier_ean']) && !empty($post['identifier_ean'])){ + $data['identifier_ean'] = $post['identifier_ean']; + } + + if (isset($post['identifier_isbn']) && !empty($post['identifier_isbn'])){ + $data['identifier_isbn'] = $post['identifier_isbn']; + } + + if (isset($post['identifier_upc']) && !empty($post['identifier_upc'])){ + $data['identifier_upc'] = $post['identifier_upc']; + } + + $data['auction_duration'] = $post['duration']; + $data['condition'] = (isset($post['condition']) && $post['condition'] != 0 ? $post['condition'] : ''); + $data['auction_type'] = 'FixedPriceItem'; + $data['catalog_epid'] = (isset($post['catalog_epid']) && $post['catalog_epid'] != 0 ? $post['catalog_epid'] : ''); + $data['identifier_upc'] = (isset($post['identifier_upc']) && $post['identifier_upc'] != '' ? $post['identifier_upc'] : ''); + $data['identifier_isbn'] = (isset($post['identifier_isbn']) && $post['identifier_isbn'] != '' ? $post['identifier_isbn'] : ''); + $data['identifier_ean'] = (isset($post['identifier_ean']) && $post['identifier_ean'] != '' ? $post['identifier_ean'] : ''); + + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + $data['paypal_email'] = $this->config->get('ebay_payment_paypal_address'); + $data['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + + if (isset($profile_return['data']['returns_accepted'])) { + $data['returns_accepted'] = $profile_return['data']['returns_accepted']; + } + if (isset($profile_return['data']['returns_policy'])) { + $data['return_policy'] = $profile_return['data']['returns_policy']; + } + if (isset($profile_return['data']['returns_option'])) { + $data['returns_option'] = $profile_return['data']['returns_option']; + } + if (isset($profile_return['data']['returns_within'])) { + $data['returns_within'] = $profile_return['data']['returns_within']; + } + if (isset($profile_return['data']['returns_shipping'])) { + $data['returns_shipping'] = $profile_return['data']['returns_shipping']; + } + if (isset($profile_return['data']['returns_restocking_fee'])) { + $data['returns_restocking_fee'] = $profile_return['data']['returns_restocking_fee']; + } + + $data['location'] = $profile_shipping['data']['location']; + $data['postcode'] = $profile_shipping['data']['postcode']; + $data['dispatch_time'] = $profile_shipping['data']['dispatch_time']; + + if (isset($profile_shipping['data']['country'])) { + $data['country'] = $profile_shipping['data']['country']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_dropoff'])) { + $data['eligible_for_pickup_dropoff'] = $profile_shipping['data']['eligible_for_pickup_dropoff']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_instore'])) { + $data['eligible_for_pickup_instore'] = $profile_shipping['data']['eligible_for_pickup_instore']; + } + + if (isset($profile_shipping['data']['global_shipping'])) { + $data['global_shipping'] = $profile_shipping['data']['global_shipping']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount'])) { + $data['promotional_shipping_discount'] = $profile_shipping['data']['promotional_shipping_discount']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount_international'])) { + $data['promotional_shipping_discount_international'] = $profile_shipping['data']['promotional_shipping_discount_international']; + } + + $data['get_it_fast'] = (isset($profile_shipping['data']['get_it_fast']) ? $profile_shipping['data']['get_it_fast'] : 0); + + if (isset($profile_template['data']['ebay_template_id'])) { + $template = $this->model_extension_openbay_ebay_template->get($profile_template['data']['ebay_template_id']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + $data['template'] = $profile_template['data']['ebay_template_id']; + } else { + $data['template_html'] = ''; + $data['template'] = ''; + } + + $data['gallery_plus'] = $profile_template['data']['ebay_gallery_plus']; + $data['gallery_super'] = $profile_template['data']['ebay_supersize']; + + $data['private_listing'] = $profile_generic['data']['private_listing']; + + //product attributes - this is just a direct pass through used with the template tag + $data['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($post['product_id']))); + + $data['payments'] = array(); + foreach($payments as $payment) { + if ($payments_accepted[$payment['ebay_name']] == 1) { + $data['payments'][$payment['ebay_name']] = 1; + } + } + + $data['main_image'] = 0; + $data['img'] = array(); + + $product_images = $this->model_catalog_product->getProductImages($post['product_id']); + + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $data['img'][] = $product_info['image']; + } + + if (isset($profile_template['data']['ebay_img_ebay']) && $profile_template['data']['ebay_img_ebay'] == 1) { + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $data['img'][] = $product_image['image']; + } + } + } + + if (isset($profile_template['data']['ebay_img_template']) && $profile_template['data']['ebay_img_template'] == 1) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + + //if the user has not set the exclude default image, add it to the array for theme images. + $key_offset = 0; + if (!isset($profile_template['data']['default_img_exclude']) || $profile_template['data']['default_img_exclude'] != 1) { + $tmp_gallery_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + $key_offset = 1; + } + + //loop through the product images and add them. + foreach ($product_images as $k => $v) { + $tmp_gallery_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $weight_parts = explode('.', $product_info['weight']); + + // package size and weights + $data['package']['depth'] = $product_info['height']; + $data['package']['irregular'] = 0; + $data['package']['length'] = $product_info['length']; + $data['package']['unit'] = $this->config->get('ebay_measurement'); + $data['package']['weight_major'] = (int)$weight_parts[0]; + $data['package']['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + $data['package']['width'] = $product_info['width']; + + $package_types = $this->openbay->ebay->getSetting('package_type'); + + foreach ($package_types as $package_type) { + if ($package_type['default'] == 1) { + $data['package']['package'] = $package_type['code']; + } + } + + $data = array_merge($data, $profile_shipping['data']); + + $verify_response = $this->model_extension_openbay_ebay->ebayAddItem($data, 'no'); + + $json = array( + 'errors' => $verify_response['data']['Errors'], + 'fees' => $verify_response['data']['Fees'], + 'itemid' => (string)$verify_response['data']['ItemID'], + 'preview' => (string)$verify_response['data']['link'], + 'i' => $this->request->get['i'], + 'ack' => (string)$verify_response['data']['Ack'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function repairLinks() { + $this->load->model('extension/openbay/ebay_product'); + + $this->model_extension_openbay_ebay_product->repairLinks(); + + $json = array('msg' => 'Links repaired'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function deleteAllLocks() { + $this->openbay->ebay->log('deleteAllLocks() - Deleting all locks'); + $this->db->query("DELETE FROM `" . DB_PREFIX . "ebay_order_lock`"); + + $json = array('msg' => 'Locks deleted'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function endItem() { + $json = $this->openbay->ebay->endItem($this->request->get['item_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPartsCompatibilityOptions() { + $this->load->model('extension/openbay/ebay_product'); + + $json = $this->model_extension_openbay_ebay_product->getPartsCompatibilityOptions($this->request->get['category_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPartsCompatibilityValues() { + $this->load->model('extension/openbay/ebay_product'); + + $property_filter = array(); + + if (isset($this->request->post['filters']) && !empty($this->request->post['filters'])) { + $post_filters = $this->request->post['filters']; + + foreach ($post_filters as $filter) { + $property_filter[] = array( + 'property_filter_name' => $filter['property_filter_name'], + 'property_filter_value' => $filter['property_filter_value'], + ); + } + } + + $filters = array( + 'category_id' => $this->request->get['category_id'], + 'property_name' => $this->request->get['option_name'], + 'property_filter' => $property_filter, + ); + + $json = $this->model_extension_openbay_ebay_product->getPartsCompatibilityValues($filters); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getItemRecommendations() { + $this->load->language('extension/openbay/ebay_edit'); + $this->load->model('extension/openbay/ebay_product'); + + if (!isset($this->request->get['item_id']) || empty($this->request->get['item_id'])) { + $json = array( + 'error' => true, + 'msg' => $this->language->get('error_no_item_id'), + ); + } else { + $filters = array(); + + $filters['item_id'] = $this->request->get['item_id']; + + if (isset($this->request->get['recommendation_type'])) { + $filters['recommendation_type'] = $this->request->get['recommendation_type']; + } + + $json = $this->model_extension_openbay_ebay_product->getItemRecommendations($filters); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/openbay/ebay_profile.php b/public/admin/controller/extension/openbay/ebay_profile.php new file mode 100644 index 0000000..082ddb2 --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay_profile.php @@ -0,0 +1,364 @@ +<?php +class ControllerExtensionOpenbayEbayProfile extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_profile'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['add'] = $this->url->link('extension/openbay/ebay_profile/add', 'user_token=' . $this->session->data['user_token'], true); + $data['types'] = $this->model_extension_openbay_ebay_profile->getTypes(); + $data['profiles'] = $this->model_extension_openbay_ebay_profile->getAll(); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_profile_list', $data)); + + } + + public function add() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->document->setTitle($data['heading_title']); + + $this->load->model('extension/openbay/ebay_profile'); + + if (!isset($this->request->post['step1'])) { + if ($this->request->post && $this->profileValidate()) { + $this->session->data['success'] = $data['text_added']; + + $this->model_extension_openbay_ebay_profile->add($this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + $this->form($data); + } + + public function delete() { + $this->load->model('extension/openbay/ebay_profile'); + + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_profile')) { + $this->error['warning'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['ebay_profile_id'])) { + $this->model_extension_openbay_ebay_profile->delete($this->request->get['ebay_profile_id']); + } + } + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function edit() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->document->setTitle($data['heading_title']); + + $this->load->model('extension/openbay/ebay_profile'); + + if ($this->request->post && $this->profileValidate()) { + $this->session->data['success'] = $data['text_updated']; + + $this->model_extension_openbay_ebay_profile->edit($this->request->post['ebay_profile_id'], $this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->form($data); + } + + public function form($data) { + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + + $data['user_token'] = $this->session->data['user_token']; + $data['shipping_international_zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + $data['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $data['types'] = $this->model_extension_openbay_ebay_profile->getTypes(); + + $setting = array(); + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + $setting['shipping_types'] = $this->openbay->ebay->getSetting('shipping_types'); + $setting['listing_restrictions'] = $this->openbay->ebay->getSetting('listing_restrictions'); + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $data['setting'] = $setting; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $profile_info = array(); + if (isset($this->request->get['ebay_profile_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $profile_info = $this->model_extension_openbay_ebay_profile->get($this->request->get['ebay_profile_id']); + $data['text_manage'] = $this->language->get('text_edit'); + $data['action'] = $this->url->link('extension/openbay/ebay_profile/edit', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/openbay/ebay_profile/add', 'user_token=' . $this->session->data['user_token'], true); + $data['text_manage'] = $this->language->get('text_add'); + } + + $data['cancel'] = $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['type'])) { + $type = $this->request->post['type']; + } else { + $type = $profile_info['type']; + } + + if (!array_key_exists($type, $data['types'])) { + $this->session->data['error'] = $data['error_no_template']; + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title') + ); + + if (isset($this->request->post['default'])) { + $data['default'] = $this->request->post['default']; + } elseif (!empty($profile_info)) { + $data['default'] = $profile_info['default']; + } else { + $data['default'] = 0; + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($profile_info)) { + $data['name'] = $profile_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($profile_info)) { + $data['description'] = $profile_info['description']; + } else { + $data['description'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } else { + $data['type'] = $profile_info['type']; + } + + if (isset($this->request->get['ebay_profile_id'])) { + $data['ebay_profile_id'] = $this->request->get['ebay_profile_id']; + } else { + $data['ebay_profile_id'] = ''; + } + + if (isset($this->request->post['data'])) { + $data['data'] = $this->request->post['data']; + } elseif (!empty($profile_info)) { + $data['data'] = $profile_info['data']; + } else { + $data['data'] = array(); + } + + if ($type == 0) { + $data['zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + $data['data']['national']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'calculated'); + $data['data']['national']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'flat'); + $data['data']['international']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'calculated'); + $data['data']['international']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'flat'); + + $data['data']['national']['calculated']['count'] = isset($data['data']['national']['calculated']['service_id']) ? max(array_keys($data['data']['national']['calculated']['service_id']))+1 : 0; + $data['data']['national']['flat']['count'] = isset($data['data']['national']['flat']['service_id']) ? max(array_keys($data['data']['national']['flat']['service_id']))+1 : 0; + $data['data']['international']['calculated']['count'] = isset($data['data']['international']['calculated']['service_id']) ? max(array_keys($data['data']['international']['calculated']['service_id']))+1 : 0; + $data['data']['international']['flat']['count'] = isset($data['data']['international']['flat']['service_id']) ? max(array_keys($data['data']['international']['flat']['service_id']))+1 : 0; + + $payment_types = $this->model_extension_openbay_ebay->getPaymentTypes(); + $data['cod_surcharge'] = 0; + + foreach($payment_types as $payment) { + if ($payment['ebay_name'] == 'COD') { + $data['cod_surcharge'] = 1; + } + } + + if (!isset($data['data']['national']['shipping_type'])) { + $data['data']['national']['shipping_type'] = 'flat'; + } + + if (!isset($data['data']['international']['shipping_type'])) { + $data['data']['international']['shipping_type'] = 'flat'; + } + + $data['html_national_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_flat', $data); + $data['html_international_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_flat', $data); + $data['html_national_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_calculated', $data); + $data['html_international_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_calculated', $data); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view($data['types'][$type]['template'], $data)); + } + + public function get() { + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->language('extension/openbay/ebay_profile'); + + $profile_info = $this->model_extension_openbay_ebay_profile->get($this->request->get['ebay_profile_id']); + $data = array(); + + if ($profile_info['type'] == 0) { + $data['data'] = $profile_info['data']; + $data['data']['national']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'calculated'); + $data['data']['international']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'calculated'); + $data['data']['national']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'flat'); + $data['data']['international']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'flat'); + + $data['data']['national']['calculated']['count'] = isset($data['data']['national']['calculated']['service_id']) ? max(array_keys($data['data']['national']['calculated']['service_id']))+1 : 0; + $data['data']['national']['flat']['count'] = isset($data['data']['national']['flat']['service_id']) ? max(array_keys($data['data']['national']['flat']['service_id']))+1 : 0; + $data['data']['international']['calculated']['count'] = isset($data['data']['international']['calculated']['service_id']) ? max(array_keys($data['data']['international']['calculated']['service_id']))+1 : 0; + $data['data']['international']['flat']['count'] = isset($data['data']['international']['flat']['service_id']) ? max(array_keys($data['data']['international']['flat']['service_id']))+1 : 0; + + $data['zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + $data['text_shipping_service'] = $this->language->get('text_shipping_service'); + $data['text_shipping_first'] = $this->language->get('text_shipping_first'); + $data['button_delete'] = $this->language->get('button_delete'); + $data['text_shipping_zones'] = $this->language->get('text_shipping_zones'); + $data['text_shipping_worldwide'] = $this->language->get('text_shipping_worldwide'); + $data['text_shipping_add'] = $this->language->get('text_shipping_add'); + $data['text_cod_surcharge'] = $this->language->get('text_cod_surcharge'); + + $payment_types = $this->model_extension_openbay_ebay->getPaymentTypes(); + $data['cod_surcharge'] = 0; + + if (!empty($payment_types)) { + foreach($payment_types as $payment) { + if ($payment['ebay_name'] == 'COD') { + $data['cod_surcharge'] = 1; + } + } + } + $return['national']['type'] = $data['data']['national']['shipping_type']; + $return['international']['type'] = $data['data']['international']['shipping_type']; + + $return['national_flat_count'] = (int)$data['data']['national']['flat']['count']; + $return['national_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_flat', $data); + + $return['international_flat_count'] = (int)$data['data']['international']['flat']['count']; + $return['international_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_flat', $data); + + $return['national_calculated_count'] = (int)$data['data']['national']['calculated']['count']; + $return['national_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_calculated', $data); + + $return['international_calculated_count'] = (int)$data['data']['international']['flat']['count']; + $return['international_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_calculated', $data); + + $profile_info['html'] = $return; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($profile_info)); + } + + private function profileValidate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_profile')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['name'] == '') { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/ebay_template.php b/public/admin/controller/extension/openbay/ebay_template.php new file mode 100644 index 0000000..131ac14 --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay_template.php @@ -0,0 +1,216 @@ +<?php +class ControllerExtensionOpenbayEbayTemplate extends Controller { + private $error = array(); + + public function listAll() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['add'] = $this->url->link('extension/openbay/ebay_template/add', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + + $data['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_template_list', $data)); + } + + public function add() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $data['page_title'] = $data['heading_title']; + $data['btn_save'] = $this->url->link('extension/openbay/ebay_template/add', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->request->post && $this->templateValidate()) { + $this->session->data['success'] = $data['text_added']; + + $this->model_extension_openbay_ebay_template->add($this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->templateForm($data); + } + + public function delete() { + $this->load->language('extension/openbay/ebay_template'); + $this->load->model('extension/openbay/ebay_template'); + + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_template')) { + $this->error['warning'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['template_id'])) { + $this->model_extension_openbay_ebay_template->delete($this->request->get['template_id']); + + $this->session->data['success'] = $this->language->get('text_deleted'); + } + } + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function edit() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $this->document->setTitle($data['heading_title']); + + $data['btn_save'] = $this->url->link('extension/openbay/ebay_template/edit', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->request->post && $this->templateValidate()) { + + $this->session->data['success'] = $data['text_updated']; + + $this->model_extension_openbay_ebay_template->edit($this->request->post['template_id'], $this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->templateForm($data); + } + + public function templateForm($data) { + $this->load->model('extension/openbay/ebay'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->get['template_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $template_info = $this->model_extension_openbay_ebay_template->get($this->request->get['template_id']); + $data['text_manage'] = $this->language->get('text_edit'); + } else { + $data['text_manage'] = $this->language->get('text_add'); + } + + $this->document->setTitle($data['heading_title']); + + $this->document->addStyle('view/javascript/codemirror/lib/codemirror.css'); + $this->document->addStyle('view/javascript/codemirror/theme/monokai.css'); + $this->document->addScript('view/javascript/codemirror/lib/codemirror.js'); + $this->document->addScript('view/javascript/codemirror/lib/formatting.js'); + $this->document->addScript('view/javascript/codemirror/lib/xml.js'); + + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'OpenBay Pro', + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'eBay', + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'Profiles', + ); + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($template_info)) { + $data['name'] = $template_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['html'])) { + $data['html'] = $this->request->post['html']; + } elseif (!empty($template_info)) { + $data['html'] = $template_info['html']; + } else { + $data['html'] = ''; + } + + if (isset($this->request->get['template_id'])) { + $data['template_id'] = $this->request->get['template_id']; + } else { + $data['template_id'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_template_form', $data)); + } + + private function templateValidate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_template')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['name'] == '') { + $this->error['warning'] = $this->language->get('error_name'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/etsy.php b/public/admin/controller/extension/openbay/etsy.php new file mode 100644 index 0000000..125dae6 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy.php @@ -0,0 +1,233 @@ +<?php +class ControllerExtensionOpenbayEtsy extends Controller { + public function install() { + $this->load->language('extension/openbay/etsy'); + $this->load->model('extension/openbay/etsy'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shipping'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shipping'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shop'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shop'); + + $this->model_extension_openbay_etsy->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/etsy'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_etsy->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/etsy'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $data['validation'] = $this->openbay->etsy->validate(); + $data['links_settings'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['links_products'] = $this->url->link('extension/openbay/etsy_product/links', 'user_token=' . $this->session->data['user_token'], true); + $data['links_listings'] = $this->url->link('extension/openbay/etsy_product/listings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=etsy'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy', $data)); + } + + public function settings() { + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/etsy'); + $this->load->model('localisation/order_status'); + + $this->load->language('extension/openbay/etsy_settings'); + + $data = $this->language->all(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('etsy', $this->request->post); + + $this->openbay->etsy->resetConfig($this->request->post['etsy_token'], $this->request->post['etsy_encryption_key']); + + $account_info = $this->model_extension_openbay_etsy->verifyAccount(); + + if (isset($account_info['header_code']) && $account_info['header_code'] == 200) { + $this->openbay->etsy->settingsUpdate(); + + $this->session->data['success'] = $this->language->get('text_success'); + } else { + $this->session->data['error'] = $this->language->get('error_account_info'); + } + + $this->response->redirect($this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['etsy_status'])) { + $data['etsy_status'] = $this->request->post['etsy_status']; + } else { + $data['etsy_status'] = $this->config->get('etsy_status'); + } + + if (isset($this->request->post['etsy_token'])) { + $data['etsy_token'] = $this->request->post['etsy_token']; + } else { + $data['etsy_token'] = $this->config->get('etsy_token'); + } + + if (isset($this->request->post['etsy_encryption_key'])) { + $data['etsy_encryption_key'] = $this->request->post['etsy_encryption_key']; + } else { + $data['etsy_encryption_key'] = $this->config->get('etsy_encryption_key'); + } + + if (isset($this->request->post['etsy_encryption_iv'])) { + $data['etsy_encryption_iv'] = $this->request->post['etsy_encryption_iv']; + } else { + $data['etsy_encryption_iv'] = $this->config->get('etsy_encryption_iv'); + } + + if (isset($this->request->post['etsy_address_format'])) { + $data['etsy_address_format'] = $this->request->post['etsy_address_format']; + } else { + $data['etsy_address_format'] = $this->config->get('etsy_address_format'); + } + + if (isset($this->request->post['etsy_order_status_new'])) { + $data['etsy_order_status_new'] = $this->request->post['etsy_order_status_new']; + } else { + $data['etsy_order_status_new'] = $this->config->get('etsy_order_status_new'); + } + + if (isset($this->request->post['etsy_order_status_paid'])) { + $data['etsy_order_status_paid'] = $this->request->post['etsy_order_status_paid']; + } else { + $data['etsy_order_status_paid'] = $this->config->get('etsy_order_status_paid'); + } + + if (isset($this->request->post['etsy_order_status_shipped'])) { + $data['etsy_order_status_shipped'] = $this->request->post['etsy_order_status_shipped']; + } else { + $data['etsy_order_status_shipped'] = $this->config->get('etsy_order_status_shipped'); + } + + if (isset($this->request->post['etsy_logging'])) { + $data['etsy_logging'] = $this->request->post['etsy_logging']; + } else { + $data['etsy_logging'] = $this->config->get('etsy_logging'); + } + + $data['api_server'] = $this->openbay->etsy->getServer(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['account_info'] = $this->model_extension_openbay_etsy->verifyAccount(); + $data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=etsy'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_settings', $data)); + } + + public function settingsUpdate() { + $this->openbay->etsy->settingsUpdate(); + + $response = array('header_code' => 200); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getOrders() { + $response = $this->openbay->etsy->call('v1/etsy/order/get/all/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/etsy')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/etsy_product.php b/public/admin/controller/extension/openbay/etsy_product.php new file mode 100644 index 0000000..c1076da --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_product.php @@ -0,0 +1,761 @@ +<?php +class ControllerExtensionOpenbayEtsyProduct extends Controller { + private $error; + + public function create() { + $this->load->language('extension/openbay/etsy_create'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $data['action'] = $this->url->link('extension/openbay/etsy_product/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $this->load->model('tool/image'); + + if (!empty($product_info) && is_file(DIR_IMAGE . $product_info['image'])) { + $product_info['image_url'] = $this->model_tool_image->resize($product_info['image'], 800, 800); + $product_info['thumb'] = $this->model_tool_image->resize($product_info['image'], 100, 100); + } else { + $product_info['image_url'] = ''; + $product_info['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + // Images + if (isset($this->request->get['product_id'])) { + $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); + } else { + $product_images = array(); + } + + $data['product_images'] = array(); + + foreach ($product_images as $product_image) { + if (is_file(DIR_IMAGE . $product_image['image'])) { + $image = $product_image['image']; + } else { + $image = ''; + } + + $product_info['product_images'][] = array( + 'image_url' => $this->model_tool_image->resize($image, 800, 800), + 'thumb' => $this->model_tool_image->resize($image, 100, 100), + 'sort_order' => $product_image['sort_order'] + ); + } + + $data['product'] = $product_info; + $data['product']['description_raw'] = trim(strip_tags(html_entity_decode($data['product']['description'], ENT_QUOTES, 'UTF-8'))); + + $setting = array(); + + $setting['who_made'] = $this->openbay->etsy->getSetting('who_made'); + if (is_array($setting['who_made'])) { + ksort($setting['who_made']); + } + + $setting['when_made'] = $this->openbay->etsy->getSetting('when_made'); + if (is_array($setting['when_made'])) { + ksort($setting['when_made']); + } + + $setting['recipient'] = $this->openbay->etsy->getSetting('recipient'); + if (is_array($setting['recipient'])) { + ksort($setting['recipient']); + } + + $setting['occasion'] = $this->openbay->etsy->getSetting('occasion'); + if (is_array($setting['occasion'])) { + ksort($setting['occasion']); + } + + $setting['state'] = array('active', 'draft'); + + $data['setting'] = $setting; + + if ($product_info['quantity'] > 999) { + $this->error['warning'] = sprintf($this->language->get('error_stock_max'), $product_info['quantity']); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $data['error_variant'] = $this->language->get('error_variant'); + } else { + $data['error_variant'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_create', $data)); + } + + public function createSubmit() { + $this->load->language('extension/openbay/etsy_create'); + $this->load->model('extension/openbay/etsy_product'); + + $data = $this->request->post; + + // validation + if (!isset($data['title']) || empty($data['title']) || strlen($data['title']) > 255) { + if (strlen($data['title']) > 255) { + $this->error['title'] = $this->language->get('error_title_length'); + } else { + $this->error['title'] = $this->language->get('error_title_missing'); + } + } + + if (!isset($data['description']) || empty($data['description'])) { + $this->error['title'] = $this->language->get('error_desc_missing'); + } + + if (!isset($data['price']) || empty($data['price'])) { + $this->error['price'] = $this->language->get('error_price_missing'); + } + + if (!isset($data['taxonomy_id']) || empty($data['taxonomy_id']) || $data['taxonomy_id'] == 0) { + $this->error['taxonomy_id'] = $this->language->get('error_category'); + } + + if (isset($data['tags']) && count($data['tags']) > 13) { + $this->error['tags'] = $this->language->get('error_tags'); + } + + if (isset($data['materials']) && count($data['materials']) > 13) { + $this->error['materials'] = $this->language->get('error_materials'); + } + + if (isset($data['style_1']) && !empty($data['style_1'])) { + if (preg_match('/[^\p{L}\p{Nd}\p{Zs}]/u', $data['style_1']) == 1) { + $this->error['style_1'] = $this->language->get('error_style_1_tag'); + } + } + + if (isset($data['style_2']) && !empty($data['style_2'])) { + if (preg_match('/[^\p{L}\p{Nd}\p{Zs}]/u', $data['style_2']) == 1) { + $this->error['style_2'] = $this->language->get('error_style_2_tag'); + } + } + + if ($data['quantity'] > 999) { + $this->error['quantity'] = sprintf($this->language->get('error_stock_max'), $data['quantity']); + } + + if (isset($data['product_image']) && count($data['product_image']) > 4) { + $this->error['images'] = sprintf($this->language->get('error_image_max'), count($data['product_image'])+1); + } + + if (!$this->error) { + // process the request + $response = $this->openbay->etsy->call('v1/etsy/product/listing/create/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['results'][0]['listing_id'])) { + $this->model_extension_openbay_etsy_product->addLink($data['product_id'], $response['data']['results'][0]['listing_id'], 1); + } + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } else { + $this->response->setOutput(json_encode(array('error' => $this->error))); + } + } + + public function edit() { + $this->load->language('extension/openbay/etsy_edit'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/etsy_product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/etsy_product/editSubmit', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $links = $this->openbay->etsy->getLinks($this->request->get['product_id'], 1, 1); + + $data['listing'] = $this->openbay->etsy->getEtsyItem($links[0]['etsy_item_id']); + + $data['etsy_item_id'] = $links[0]['etsy_item_id']; + $data['product_id'] = $this->request->get['product_id']; + + $setting['state'] = array('active', 'inactive', 'draft'); + + $data['setting'] = $setting; + + if ($data['listing']['state'] == 'edit') { + $data['listing']['state'] = 'inactive'; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_edit', $data)); + } + + public function editSubmit() { + $this->load->language('extension/openbay/etsy_edit'); + $this->load->model('extension/openbay/etsy_product'); + + $data = $this->request->post; + + // validation + if (!isset($data['title']) || empty($data['title']) || strlen($data['title']) > 255) { + if (strlen($data['title']) > 255) { + $this->error['title'] = $this->language->get('error_title_length'); + } else { + $this->error['title'] = $this->language->get('error_title_missing'); + } + } + + if (!isset($data['description']) || empty($data['description'])) { + $this->error['title'] = $this->language->get('error_desc_missing'); + } + + if (!isset($data['price']) || empty($data['price'])) { + $this->error['price'] = $this->language->get('error_price_missing'); + } + + if (!isset($data['state']) || empty($data['state'])) { + $this->error['state'] = $this->language->get('error_state_missing'); + } + + if (!$this->error) { + // process the request + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . $data['etsy_item_id'] . '/update/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } else { + $this->response->setOutput(json_encode(array('error' => $this->error))); + } + } + + public function addImage() { + $this->load->language('extension/openbay/etsy_create'); + + $data = $this->request->post; + + if (!isset($data['image']) || empty($data['image'])) { + $this->error['image'] = $this->language->get('error_no_img_url'); + } + + if (!isset($data['listing_id']) || empty($data['listing_id'])) { + $this->error['listing_id'] = $this->language->get('error_no_listing_id'); + } + + if (!$this->error) { + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['listing_id'] . '/image/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } + } + + public function getCategories() { + $categories = $this->cache->get('etsy_categories'); + + if (!$categories) { + $response = $this->openbay->etsy->call('v1/etsy/product/taxonomy/', 'GET'); + + if (isset($response['header_code']) && $response['header_code'] == 200) { + $categories = $this->formatCategories($response['data']['data']['results']); + + /** + * Need to create cache instance here due to bug where all caches expire after 3600 seconds. + **/ + $etsy_cache = new Cache('file', 3000000); + + $etsy_cache->set('etsy_categories', $categories); + } + } + + $response = array(); + $parent_categories = array(); + $last_id = 0; + + if (isset($this->request->get['id_path']) && $this->request->get['id_path'] != '' && $this->request->get['id_path'] != 0) { + $id_path_parts = explode(',', $this->request->get['id_path']); + + + foreach ($id_path_parts as $id_path) { + $parent_categories[] = $categories[$id_path]['name']; + + $categories = $categories[$id_path]['children']; + + $last_id = $id_path; + } + } + + if (empty($categories)) { + $final_category = true; + } else { + foreach ($categories as $id => $category) { + $response[$id] = array( + 'name' => $category['name'], + 'id_path' => $category['id_path'], + 'children_count' => (is_array($category['children']) ? count($category['children']) : 0), + ); + } + + $final_category = false; + } + + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('data' => $response, 'parent_text' => implode(' > ', $parent_categories), 'final_category' => $final_category, 'last_id' => $last_id))); + } + + private function formatCategories($category_data) { + $response = array(); + + foreach ($category_data as $category) { + $response[$category['id']] = array( + 'name' => $category['name'], + 'id_path' => implode(',', $category['full_path_taxonomy_ids']), + 'children' => (isset($category['children']) && !empty($category['children']) ? $this->formatCategories($category['children']) : ''), + ); + } + + return $response; + } + + public function addLink() { + $this->load->language('extension/openbay/etsy_links'); + $this->load->model('extension/openbay/etsy_product'); + $this->load->model('catalog/product'); + + $data = $this->request->post; + + if (!isset($data['product_id'])) { + echo json_encode(array('error' => $this->language->get('error_product_id'))); + die(); + } + + if (!isset($data['etsy_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $links = $this->openbay->etsy->getLinks($data['product_id'], 1); + + if ($links != false) { + echo json_encode(array('error' => $this->language->get('error_link_exists'))); + die(); + } + + $product = $this->model_catalog_product->getProduct($data['product_id']); + + if (!$product) { + echo json_encode(array('error' => $this->language->get('error_product'))); + die(); + } + + if ($product['quantity'] <= 0) { + echo json_encode(array('error' => $this->language->get('error_stock'))); + die(); + } + + // check the etsy item exists + $get_response = $this->openbay->etsy->getEtsyItem($data['etsy_id']); + + if (isset($get_response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $get_response['data']['error'])); + die(); + } else { + if ((int)$get_response['quantity'] != (int)$product['quantity']) { + // if the stock is different than the item being linked update the etsy stock level + $update_response = $this->openbay->etsy->updateListingStock($data['etsy_id'], $product['quantity'], $get_response['state']); + + if (isset($update_response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $update_response['data']['error'])); + die(); + } + } + } + + $this->model_extension_openbay_etsy_product->addLink($data['product_id'], $data['etsy_id'], 1); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + + public function deleteLink() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_link_id'])) { + echo json_encode(array('error' => $this->language->get('error_link_id'))); + die(); + } + + $this->openbay->etsy->deleteLink($data['etsy_link_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + + public function links() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/etsy_product'); + + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true); + //$data['edit_url'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=', true); + //$data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $total_linked = $this->model_extension_openbay_etsy_product->totalLinked(); + + if (isset($this->request->get['page'])){ + $page = (int)$this->request->get['page']; + } else { + $page = 1; + } + + $limit = $this->config->get('config_limit_admin'); + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $page; + $pagination->limit = $limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/etsy/itemLinks', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($total_linked - $limit)) ? $total_linked : ((($page - 1) * $limit) + $limit), $total_linked, ceil($total_linked / $limit)); + + $data['items'] = $this->model_extension_openbay_etsy_product->loadLinked($limit, $page); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_links', $data)); + } + + public function listings() { + $this->load->language('extension/openbay/etsy_listings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/etsy_product'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $filter = array(); + + if (!isset($this->request->get['status'])) { + $filter['status'] = 'active'; + } else { + $filter['status'] = $this->request->get['status']; + } + + if (!isset($this->request->get['page'])) { + $filter['page'] = 1; + } else { + $filter['page'] = $this->request->get['page']; + } + + if (isset($this->request->get['keywords'])) { + $filter['keywords'] = $this->request->get['keywords']; + } + + $filter['limit'] = (int)$this->config->get('config_limit_admin'); + + $data['filter'] = $filter; + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/all/?' . http_build_query($filter), 'GET'); + + unset($filter['page']); + + if (isset($response['data']['error'])) { + $data['listings'] = array(); + $data['pagination'] = ''; + $data['results'] = ''; + $this->error['warning'] = $this->language->get('error_etsy') . $response['data']['error']; + } else { + $listings = array(); + + foreach($response['data']['results'] as $listing) { + $product_link = $this->openbay->etsy->getLinkedProduct($listing['listing_id']); + + $actions = array(); + + if ($filter['status'] == 'inactive') { + $actions[] = 'activate_item'; + } + + if ($filter['status'] == 'active') { + $actions[] = 'end_item'; + $actions[] = 'deactivate_item'; + } + + if ($filter['status'] == 'active' && empty($product_link)) { + $actions[] = 'add_link'; + } + + if (!empty($product_link)) { + $actions[] = 'delete_link'; + } + + if ($product_link != false) { + $listings[] = array('link' => $product_link, 'listing' => $listing, 'actions' => $actions); + } else { + $listings[] = array('link' => '', 'listing' => $listing, 'actions' => $actions); + } + } + + $data['listings'] = $listings; + + $pagination = new Pagination(); + $pagination->total = $response['data']['count']; + $pagination->page = $response['data']['pagination']['effective_page']; + $pagination->limit = $response['data']['pagination']['effective_limit']; + $pagination->url = $this->url->link('extension/openbay/etsy_product/listings', 'user_token=' . $this->session->data['user_token'] . '&page={page}&' . http_build_query($filter), true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($response['data']['count']) ? (($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) + 1 : 0, ((($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) > ($response['data']['count'] - $response['data']['pagination']['effective_limit'])) ? $response['data']['count'] : ((($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) + $response['data']['pagination']['effective_limit']), $response['data']['count'], ceil($response['data']['count'] / $response['data']['pagination']['effective_limit'])); + } + + $data['success'] = ''; + + if (isset($this->request->get['item_ended'])) { + $data['success'] = $this->language->get('text_item_ended'); + } + + if (isset($this->request->get['item_activated'])) { + $data['success'] = $this->language->get('text_item_activated'); + } + + if (isset($this->request->get['item_deactivated'])) { + $data['success'] = $this->language->get('text_item_deactivated'); + } + + if (isset($this->request->get['link_added'])) { + $data['success'] = $this->language->get('text_link_added'); + } + + if (isset($this->request->get['link_deleted'])) { + $data['success'] = $this->language->get('text_link_deleted'); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_listings', $data)); + } + + public function endListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/delete/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $linked_item = $this->openbay->etsy->getLinkedProduct($data['etsy_item_id']); + + if ($linked_item != false) { + $this->openbay->etsy->deleteLink($linked_item['etsy_listing_id']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + } + + public function deactivateListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/inactive/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $linked_item = $this->openbay->etsy->getLinkedProduct($data['etsy_item_id']); + + if ($linked_item != false) { + $this->openbay->etsy->deleteLink($linked_item['etsy_listing_id']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + } + + public function activateListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + $this->response->addHeader('Content-Type: application/json'); + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/active/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $this->response->setOutput(json_encode(array('error' => false))); + } + } +} diff --git a/public/admin/controller/extension/openbay/etsy_shipping.php b/public/admin/controller/extension/openbay/etsy_shipping.php new file mode 100644 index 0000000..ecf0fe9 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_shipping.php @@ -0,0 +1,9 @@ +<?php +class ControllerExtensionOpenbayEtsyShipping extends Controller { + public function getAll() { + $response = $this->openbay->etsy->call('v1/etsy/product/shipping/getAllTemplates/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + return $this->response->setOutput(json_encode($response)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/etsy_shop.php b/public/admin/controller/extension/openbay/etsy_shop.php new file mode 100644 index 0000000..598edd9 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_shop.php @@ -0,0 +1,9 @@ +<?php +class ControllerExtensionOpenbayEtsyShop extends Controller { + public function getSections() { + $response = $this->openbay->etsy->call('v1/etsy/shop/getSections/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + return $this->response->setOutput(json_encode($response)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/fba.php b/public/admin/controller/extension/openbay/fba.php new file mode 100644 index 0000000..660e49b --- /dev/null +++ b/public/admin/controller/extension/openbay/fba.php @@ -0,0 +1,923 @@ +<?php +class ControllerExtensionOpenbayFba extends Controller { + public function install() { + $this->load->model('extension/openbay/fba'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/fba'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/fba'); + + $this->model_extension_openbay_fba->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/fba'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_fba->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/fba'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/fba'); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + $data['success'] = ''; + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->fba->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_account'] = 'https://account.openbaypro.com/fba/index/'; + $data['link_fulfillments'] = $this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'], true); + $data['link_orders'] = $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/fba/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=fba'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/fba_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/fba'); + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('openbay_fba', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_fba'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/fba/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=fba'; + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['openbay_fba_status'])) { + $data['openbay_fba_status'] = $this->request->post['openbay_fba_status']; + } else { + $data['openbay_fba_status'] = $this->config->get('openbay_fba_status'); + } + + if (isset($this->request->post['openbay_fba_api_key'])) { + $data['openbay_fba_api_key'] = trim($this->request->post['openbay_fba_api_key']); + } else { + $data['openbay_fba_api_key'] = trim($this->config->get('openbay_fba_api_key')); + } + + if (isset($this->request->post['openbay_fba_encryption_key'])) { + $data['openbay_fba_encryption_key'] = trim($this->request->post['openbay_fba_encryption_key']); + } else { + $data['openbay_fba_encryption_key'] = trim($this->config->get('openbay_fba_encryption_key')); + } + + if (isset($this->request->post['openbay_fba_encryption_iv'])) { + $data['openbay_fba_encryption_iv'] = trim($this->request->post['openbay_fba_encryption_iv']); + } else { + $data['openbay_fba_encryption_iv'] = trim($this->config->get('openbay_fba_encryption_iv')); + } + + if (isset($this->request->post['openbay_fba_api_account_id'])) { + $data['openbay_fba_api_account_id'] = trim($this->request->post['openbay_fba_api_account_id']); + } else { + $data['openbay_fba_api_account_id'] = trim($this->config->get('openbay_fba_api_account_id')); + } + + if (isset($this->request->post['openbay_fba_send_orders'])) { + $data['openbay_fba_send_orders'] = $this->request->post['openbay_fba_send_orders']; + } else { + $data['openbay_fba_send_orders'] = $this->config->get('openbay_fba_send_orders'); + } + + if (isset($this->request->post['openbay_fba_debug_log'])) { + $data['openbay_fba_debug_log'] = $this->request->post['openbay_fba_debug_log']; + } else { + $data['openbay_fba_debug_log'] = $this->config->get('openbay_fba_debug_log'); + } + + $order_total = $this->model_extension_openbay_fba->countFbaOrders(); + + if ($order_total > 0) { + $data['prefix_can_edit'] = false; + } else { + $data['prefix_can_edit'] = true; + } + + if (isset($this->request->post['openbay_fba_order_prefix'])) { + $data['openbay_fba_order_prefix'] = $this->request->post['openbay_fba_order_prefix']; + } else { + $data['openbay_fba_order_prefix'] = $this->config->get('openbay_fba_order_prefix'); + } + + if (isset($this->request->post['openbay_fba_order_trigger_status'])) { + $data['openbay_fba_order_trigger_status'] = $this->request->post['openbay_fba_order_trigger_status']; + } else { + $data['openbay_fba_order_trigger_status'] = $this->config->get('openbay_fba_order_trigger_status'); + } + + if (isset($this->request->post['openbay_fba_only_fill_complete'])) { + $data['openbay_fba_only_fill_complete'] = $this->request->post['openbay_fba_only_fill_complete']; + } else { + $data['openbay_fba_only_fill_complete'] = $this->config->get('openbay_fba_only_fill_complete'); + } + + $data['fulfillment_policy'] = array( + 'FillOrKill' => $this->language->get('text_fillorkill'), + 'FillAll' => $this->language->get('text_fillall'), + 'FillAllAvailable' => $this->language->get('text_fillallavailable'), + ); + + if (isset($this->request->post['openbay_fba_fulfill_policy'])) { + $data['openbay_fba_fulfill_policy'] = $this->request->post['openbay_fba_fulfill_policy']; + } else { + $data['openbay_fba_fulfill_policy'] = $this->config->get('openbay_fba_fulfill_policy'); + } + + $data['shipping_speed'] = array( + 'Standard' => $this->language->get('text_standard'), + 'Expedited' => $this->language->get('text_expedited'), + 'Priority' => $this->language->get('text_priority'), + ); + + if (isset($this->request->post['openbay_fba_shipping_speed'])) { + $data['openbay_fba_shipping_speed'] = $this->request->post['openbay_fba_shipping_speed']; + } else { + $data['openbay_fba_shipping_speed'] = $this->config->get('openbay_fba_shipping_speed'); + } + + $data['api_server'] = $this->openbay->fba->getServerUrl(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_settings', $data)); + } + + public function verifyCredentials() { + $this->load->language('extension/openbay/fba_settings'); + + $errors = array(); + + if (!isset($this->request->post['openbay_fba_api_key']) || empty($this->request->post['openbay_fba_api_key'])) { + $errors[] = array('message' => $this->language->get('error_api_key')); + } + + if (!isset($this->request->post['openbay_fba_api_account_id']) || empty($this->request->post['openbay_fba_api_account_id'])) { + $errors[] = array('message' => $this->language->get('error_api_account_id')); + } + + if (!isset($this->request->post['openbay_fba_encryption_key']) || empty($this->request->post['openbay_fba_encryption_key'])) { + $errors[] = array('message' => $this->language->get('error_encryption_key')); + } + + if (!isset($this->request->post['openbay_fba_encryption_iv']) || empty($this->request->post['openbay_fba_encryption_iv'])) { + $errors[] = array('message' => $this->language->get('error_encryption_iv')); + } + + if (!$errors) { + $this->openbay->fba->setApiKey($this->request->post['openbay_fba_api_key']); + $this->openbay->fba->setAccountId($this->request->post['openbay_fba_api_account_id']); + $this->openbay->fba->setEncryptionKey($this->request->post['openbay_fba_encryption_key']); + $this->openbay->fba->setEncryptionIv($this->request->post['openbay_fba_encryption_iv']); + + $response = $this->openbay->fba->call("v1/fba/status/", array(), 'GET'); + } else { + $response = array( + "result" => null, + "error" => true, + "error_messages" => $errors, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/fba')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['openbay_fba_api_key']) { + $this->error['api_key'] = $this->language->get('error_api_key'); + } + + if (!$this->request->post['openbay_fba_api_account_id']) { + $this->error['api_account_id'] = $this->language->get('error_api_account_id'); + } + + return !$this->error; + } + + public function fulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (!isset($this->request->get['fulfillment_id'])) { + $this->response->redirect($this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'] . (!empty($this->request->get['filter_date']) ? '&filter_date=' . $this->request->get['filter_date'] : ''), true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'] . (!empty($this->request->get['filter_date']) ? '&filter_date=' . $this->request->get['filter_date'] : ''), true), + 'text' => $data['heading_title'], + ); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->request->get['fulfillment_id'] . "/", array()); + $data['response'] = $response['body']; + + if ($response['error'] == true || $response['response_http'] != 200) { + $this->session->data['error'] = $this->language->get('error_loading_fulfillment'); + + $this->response->redirect($this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_fulfillment_form', $data)); + } + + public function fulfillmentList() { + $this->load->language('extension/openbay/fba_fulfillment_list'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + if (isset($this->request->get['filter_date'])) { + $data['filter_date'] = $this->request->get['filter_date']; + $request_url = "?query_start_date_time=".urlencode($this->request->get['filter_date'] . "T00:00:00Z"); + } else { + $data['filter_date'] = ''; + $request_url = ""; + } + + $data['fulfillments'] = array(); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/".$request_url, array(), 'GET'); + + if (isset($response['body']) && is_array($response['body'])) { + foreach ($response['body'] as $fulfillment_order) { + $data['fulfillments'][] = array( + 'seller_fulfillment_order_id' => $fulfillment_order['seller_fulfillment_order_id'], + 'displayable_order_id' => $fulfillment_order['displayable_order_id'], + 'displayable_order_date_time' => $fulfillment_order['displayable_order_date_time'], + 'shipping_speed_category' => $fulfillment_order['shipping_speed_category'], + 'fulfillment_order_status' => $fulfillment_order['fulfillment_order_status'], + 'edit' => $this->url->link('extension/openbay/fba/fulfillment', 'user_token=' . $this->session->data['user_token'] . '&fulfillment_id=' . $fulfillment_order['seller_fulfillment_order_id'] . (!empty($data['filter_date']) ? '&filter_date=' . $data['filter_date'] : ''), true), + ); + } + } + + $data['cancel'] = $this->url->link('extension/openbay/fba/index', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_fulfillment_list', $data)); + } + + public function shipFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id']) || empty($this->request->get['fba_order_fulfillment_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + $fba_order_fulfillment_id = (int)$this->request->get['fba_order_fulfillment_id']; + + $this->openbay->fba->log('shipFulfillment request for order ID: ' . $order_id . ', Fulfillment ID: ' . $fba_order_fulfillment_id); + + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 1); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_order_fulfillment_id . "/ship/", array(), 'GET'); + + + + if (!isset($response['response_http']) || $response['response_http'] != 200) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + + //$this->openbay->fba->updateFBAOrderStatus($order_id, 1); + } else { + $this->openbay->fba->populateFBAFulfillment(json_encode(array()), json_encode($response), $response['response_http'], $fba_fulfillment_id); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 3); + + $this->session->data['success'] = $this->language->get('text_fulfillment_shipped'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function cancelFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id']) || empty($this->request->get['fba_order_fulfillment_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + $fba_order_fulfillment_id = (int)$this->request->get['fba_order_fulfillment_id']; + + $this->openbay->fba->log('cancelFulfillment request for order ID: ' . $order_id . ', Fulfillment ID: ' . $fba_order_fulfillment_id); + + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 2); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_order_fulfillment_id . "/cancel/", array(), 'POST'); + + if (!isset($response['response_http']) || $response['response_http'] != 200) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + } else { + $this->openbay->fba->populateFBAFulfillment(json_encode(array()), json_encode($response), $response['response_http'], $fba_fulfillment_id); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 4); + + $this->session->data['success'] = $this->language->get('text_fulfillment_cancelled'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function resendFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + + $this->openbay->fba->log('resendFulfillment request for order ID: ' . $order_id); + + $this->load->model('sale/order'); + $this->load->model('catalog/product'); + + $order = $this->model_sale_order->getOrder($order_id); + + if ($order['shipping_method']) { + if ($this->config->get('openbay_fba_order_trigger_status') == $order['order_status_id']) { + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 1); + + $order_products = $this->model_sale_order->getOrderProducts($order_id); + + $fulfillment_items = array(); + + foreach ($order_products as $order_product) { + $product = $this->model_catalog_product->getProduct($order_product['product_id']); + + if ($product['location'] == 'FBA') { + $fulfillment_items[] = array( + 'seller_sku' => $product['sku'], + 'quantity' => $order_product['quantity'], + 'seller_fulfillment_order_item_id' => $this->config->get('openbay_fba_order_prefix') . $fba_fulfillment_id . '-' . $order_product['order_product_id'], + 'per_unit_declared_value' => array( + 'currency_code' => $order['currency_code'], + 'value' => number_format($order_product['price'], 2) + ), + ); + } + } + + $total_fulfillment_items = count($fulfillment_items); + + if (!empty($fulfillment_items)) { + $request = array(); + + $datetime = new DateTime($order['date_added']); + $request['displayable_order_datetime'] = $datetime->format(DateTime::ISO8601); + + $request['seller_fulfillment_order_id'] = $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_fulfillment_id; + $request['displayable_order_id'] = $order_id; + $request['displayable_order_comment'] = 'none'; + $request['shipping_speed_category'] = $this->config->get('openbay_fba_shipping_speed'); + $request['fulfillment_action'] = ($this->config->get('openbay_fba_send_orders') == 1 ? 'Ship' : 'Hold'); + $request['fulfillment_policy'] = $this->config->get('openbay_fba_fulfill_policy'); + + $request['destination_address'] = array( + 'name' => $order['shipping_firstname'] . ' ' . $order['shipping_lastname'], + 'line_1' => (!empty($order['shipping_company']) ? $order['shipping_company'] : $order['shipping_address_1']), + 'line_2' => (!empty($order['shipping_company']) ? $order['shipping_address_1'] : $order['shipping_address_2']), + 'line_3' => (!empty($order['shipping_company']) ? $order['shipping_address_2'] : ''), + 'state_or_province_code' => $order['shipping_zone'], + 'city' => $order['shipping_city'], + 'country_code' => $order['shipping_iso_code_2'], + 'postal_code' => $order['shipping_postcode'], + ); + + $request['items'] = $fulfillment_items; + + $response = $this->openbay->fba->call("v1/fba/fulfillments/", $request, 'POST'); + + if ($response['response_http'] != 201) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 1); + } else { + if ($this->config->get('openbay_fba_send_orders') == 1) { + $this->openbay->fba->updateFBAOrderStatus($order_id, 3); + } else { + $this->openbay->fba->updateFBAOrderStatus($order_id, 2); + } + + $this->openbay->fba->updateFBAOrderRef($order_id, $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_fulfillment_id); + + $this->session->data['success'] = $this->language->get('text_fulfillment_sent'); + } + + $this->openbay->fba->populateFBAFulfillment(json_encode($request), json_encode($response), $response['response_http'], $fba_fulfillment_id); + $this->openbay->fba->updateFBAOrderFulfillmentID($order_id, $fba_fulfillment_id); + } else { + $errors[] = $this->language->get('error_no_items'); + } + } + } else { + $errors[] = $this->language->get('error_no_shipping'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function orderList() { + $this->load->language('extension/openbay/fba_order'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $filters = array(); + + $url = ''; + + if (isset($this->request->get['filter_start'])) { + $filters['filter_start'] = $this->request->get['filter_start']; + $data['filter_start'] = $this->request->get['filter_start']; + $url .= "&filter_start=".urlencode($this->request->get['filter_start']); + } else { + $filters['filter_start'] = null; + $data['filter_start'] = null; + } + + if (isset($this->request->get['filter_end'])) { + $filters['filter_end'] = $this->request->get['filter_end']; + $data['filter_end'] = $this->request->get['filter_end']; + $url .= "&filter_end=".urlencode($this->request->get['filter_end']); + } else { + $filters['filter_end'] = null; + $data['filter_end'] = null; + } + + if (isset($this->request->get['filter_status'])) { + $filters['filter_status'] = $this->request->get['filter_status']; + $data['filter_status'] = $this->request->get['filter_status']; + $url .= "&filter_status=".urlencode($this->request->get['filter_status']); + } else { + $filters['filter_status'] = null; + $data['filter_status'] = null; + } + + $data['orders'] = array(); + + $orders = $this->openbay->fba->getFBAOrders($filters); + + if (!empty($orders)) { + foreach ($orders as $order) { + $data['orders'][] = array( + 'order_id' => $order['order_id'], + 'order_link' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'] . $url, true), + 'status' => $order['status'], + 'created' => $order['created'], + 'fba_item_count' => $this->openbay->fba->hasOrderFBAItems($order['order_id']), + 'view' => $this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'] . $url, true) + ); + } + } + + $data['cancel'] = $this->url->link('extension/openbay/fba/index', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['status_options'] = array( + 0 => $this->language->get('text_option_new'), + 1 => $this->language->get('text_option_error'), + 2 => $this->language->get('text_option_held'), + 3 => $this->language->get('text_option_shipped'), + ); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_order_list', $data)); + } + + public function order() { + $this->load->language('extension/openbay/fba_order'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('sale/order'); + $this->load->model('catalog/product'); + + if (!isset($this->request->get['order_id'])) { + $this->response->redirect($this->url->link('extension/openbay/fba/orderList', 'user_token=' . $this->session->data['user_token'], true)); + } + + $order_id = (int)$this->request->get['order_id']; + $order_fba = $this->openbay->fba->getFBAOrder($order_id); + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_fba['status'] == 2 || $order_fba['status'] == 3 || $order_fba['status'] == 4) { + $data['fulfillment_id'] = $order_fba['fba_order_fulfillment_ref']; + $data['fulfillment_link'] = $this->url->link('extension/openbay/fba/fulfillment', 'user_token=' . $this->session->data['user_token'] . '&fulfillment_id=' . $data['fulfillment_id'], true); + } else { + $data['fulfillment_id'] = ''; + $data['fulfillment_link'] = ''; + } + + $data['fba_order_status'] = $order_fba['status']; + $data['order_id'] = $order_id; + $data['order_link'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true); + $data['resend_link'] = $this->url->link('extension/openbay/fba/resendfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true); + $data['ship_link'] = $this->url->link('extension/openbay/fba/shipfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id . '&fba_order_fulfillment_id=' . $order_fba['fba_order_fulfillment_id'], true); + $data['cancel_link'] = $this->url->link('extension/openbay/fba/cancelfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id . '&fba_order_fulfillment_id=' . $order_fba['fba_order_fulfillment_id'], true); + + $data['cancel'] = $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $data['fulfillments'] = array(); + + if (is_array($order_fba['fulfillments'])) { + foreach ($order_fba['fulfillments'] as $fulfillment) { + $response_body = json_decode($fulfillment['response_body'], true); + + $fulfillment_errors = array(); + + if (isset($response_body['error']) && $response_body['error'] == true) { + if (is_array($response_body['error_messages']) && !empty($response_body['error_messages'])) { + $fulfillment_errors = $response_body['error_messages']; + } + } + + $data['fulfillments'][] = array( + 'fba_order_fulfillment_id' => $fulfillment['fba_order_fulfillment_id'], + 'created' => $fulfillment['created'], + 'request_body' => json_decode($fulfillment['request_body']), + 'request_body_output' => print_r(json_decode($fulfillment['request_body']), true), + 'response_body' => json_decode($fulfillment['response_body']), + 'response_body_output' => print_r(json_decode($fulfillment['response_body']), true), + 'response_header_code' => $fulfillment['response_header_code'], + 'errors' => $fulfillment_errors, + 'type' => $fulfillment['type'], + ); + } + } + + // Shipping Address + 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'] + ); + + $data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $data['status_options'] = array( + 0 => $this->language->get('text_option_new'), + 1 => $this->language->get('text_option_error'), + 2 => $this->language->get('text_option_held'), + 3 => $this->language->get('text_option_shipped'), + 4 => $this->language->get('text_option_cancelled'), + ); + + $data['type_options'] = array( + 0 => $this->language->get('text_type_new'), + 1 => $this->language->get('text_type_ship'), + 2 => $this->language->get('text_type_cancel'), + ); + + $data['products'] = array(); + + $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']); + + foreach ($products as $product) { + $option_data = array(); + + $product_info = $this->model_catalog_product->getProduct($product['product_id']); + + $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'] + ); + } + } + + $data['products'][] = array( + 'order_product_id' => $product['order_product_id'], + 'product_id' => $product['product_id'], + 'name' => $product['name'], + 'sku' => $product_info['sku'], + 'option' => $option_data, + 'quantity' => $product['quantity'], + 'fba' => ($product_info['location'] == 'FBA' ? 1 : 0), + 'href' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true), + ); + } + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_order_info', $data)); + } +} diff --git a/public/admin/controller/extension/payment/alipay.php b/public/admin/controller/extension/payment/alipay.php new file mode 100644 index 0000000..ce549b1 --- /dev/null +++ b/public/admin/controller/extension/payment/alipay.php @@ -0,0 +1,153 @@ +<?php +class ControllerExtensionPaymentAlipay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/alipay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_alipay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['merchant_private_key'])) { + $data['error_merchant_private_key'] = $this->error['merchant_private_key']; + } else { + $data['error_merchant_private_key'] = ''; + } + + if (isset($this->error['alipay_public_key'])) { + $data['error_alipay_public_key'] = $this->error['alipay_public_key']; + } else { + $data['error_alipay_public_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/alipay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/alipay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_alipay_app_id'])) { + $data['payment_alipay_app_id'] = $this->request->post['payment_alipay_app_id']; + } else { + $data['payment_alipay_app_id'] = $this->config->get('payment_alipay_app_id'); + } + + if (isset($this->request->post['payment_alipay_merchant_private_key'])) { + $data['payment_alipay_merchant_private_key'] = $this->request->post['payment_alipay_merchant_private_key']; + } else { + $data['payment_alipay_merchant_private_key'] = $this->config->get('payment_alipay_merchant_private_key'); + } + + if (isset($this->request->post['payment_alipay_alipay_public_key'])) { + $data['payment_alipay_alipay_public_key'] = $this->request->post['payment_alipay_alipay_public_key']; + } else { + $data['payment_alipay_alipay_public_key'] = $this->config->get('payment_alipay_alipay_public_key'); + } + + if (isset($this->request->post['payment_alipay_total'])) { + $data['payment_alipay_total'] = $this->request->post['payment_alipay_total']; + } else { + $data['payment_alipay_total'] = $this->config->get('payment_alipay_total'); + } + + if (isset($this->request->post['payment_alipay_order_status_id'])) { + $data['payment_alipay_order_status_id'] = $this->request->post['payment_alipay_order_status_id']; + } else { + $data['payment_alipay_order_status_id'] = $this->config->get('payment_alipay_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_alipay_geo_zone_id'])) { + $data['payment_alipay_geo_zone_id'] = $this->request->post['payment_alipay_geo_zone_id']; + } else { + $data['payment_alipay_geo_zone_id'] = $this->config->get('payment_alipay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_alipay_test'])) { + $data['payment_alipay_test'] = $this->request->post['payment_alipay_test']; + } else { + $data['payment_alipay_test'] = $this->config->get('payment_alipay_test'); + } + + if (isset($this->request->post['payment_alipay_status'])) { + $data['payment_alipay_status'] = $this->request->post['payment_alipay_status']; + } else { + $data['payment_alipay_status'] = $this->config->get('payment_alipay_status'); + } + + if (isset($this->request->post['payment_alipay_sort_order'])) { + $data['payment_alipay_sort_order'] = $this->request->post['payment_alipay_sort_order']; + } else { + $data['payment_alipay_sort_order'] = $this->config->get('payment_alipay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/alipay', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/alipay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_alipay_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_alipay_merchant_private_key']) { + $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key'); + } + + if (!$this->request->post['payment_alipay_alipay_public_key']) { + $this->error['alipay_public_key'] = $this->language->get('error_alipay_public_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/alipay_cross.php b/public/admin/controller/extension/payment/alipay_cross.php new file mode 100644 index 0000000..2026023 --- /dev/null +++ b/public/admin/controller/extension/payment/alipay_cross.php @@ -0,0 +1,163 @@ +<?php +class ControllerExtensionPaymentAlipayCross extends Controller { + private $error = array(); + private $currencies = array('GBP', 'HKD', 'USD', 'CHF', 'SGD', 'SEK', 'DKK', 'NOK', 'JPY', 'CAD', 'AUD', 'EUR', 'NZD', 'KRW', 'THB'); + + public function index() { + $this->load->language('extension/payment/alipay_cross'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_alipay_cross', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['merchant_private_key'])) { + $data['error_merchant_private_key'] = $this->error['merchant_private_key']; + } else { + $data['error_merchant_private_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/alipay_cross', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/alipay_cross', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_alipay_cross_app_id'])) { + $data['payment_alipay_cross_app_id'] = $this->request->post['payment_alipay_cross_app_id']; + } else { + $data['payment_alipay_cross_app_id'] = $this->config->get('payment_alipay_cross_app_id'); + } + + if (isset($this->request->post['payment_alipay_cross_merchant_private_key'])) { + $data['payment_alipay_cross_merchant_private_key'] = $this->request->post['payment_alipay_cross_merchant_private_key']; + } else { + $data['payment_alipay_cross_merchant_private_key'] = $this->config->get('payment_alipay_cross_merchant_private_key'); + } + + if (isset($this->request->post['payment_alipay_cross_currency'])) { + $data['payment_alipay_cross_currency'] = $this->request->post['payment_alipay_cross_currency']; + } else { + $data['payment_alipay_cross_currency'] = $this->config->get('payment_alipay_cross_currency'); + } + + $this->load->model('localisation/currency'); + + $currencies = $this->model_localisation_currency->getCurrencies(); + $data['currencies'] = array(); + foreach ($currencies as $currency) { + if (in_array($currency['code'], $this->currencies)) { + $data['currencies'][] = array( + 'code' => $currency['code'], + 'title' => $currency['title'] + ); + } + } + + if (isset($this->request->post['payment_alipay_cross_test'])) { + $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test']; + } else { + $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test'); + } + + if (isset($this->request->post['payment_alipay_cross_total'])) { + $data['payment_alipay_cross_total'] = $this->request->post['payment_alipay_cross_total']; + } else { + $data['payment_alipay_cross_total'] = $this->config->get('payment_alipay_cross_total'); + } + + if (isset($this->request->post['payment_alipay_cross_order_status_id'])) { + $data['payment_alipay_cross_order_status_id'] = $this->request->post['payment_alipay_cross_order_status_id']; + } else { + $data['payment_alipay_cross_order_status_id'] = $this->config->get('payment_alipay_cross_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_alipay_cross_geo_zone_id'])) { + $data['payment_alipay_cross_geo_zone_id'] = $this->request->post['payment_alipay_cross_geo_zone_id']; + } else { + $data['payment_alipay_cross_geo_zone_id'] = $this->config->get('payment_alipay_cross_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_alipay_cross_test'])) { + $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test']; + } else { + $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test'); + } + + if (isset($this->request->post['payment_alipay_cross_status'])) { + $data['payment_alipay_cross_status'] = $this->request->post['payment_alipay_cross_status']; + } else { + $data['payment_alipay_cross_status'] = $this->config->get('payment_alipay_cross_status'); + } + + if (isset($this->request->post['payment_alipay_cross_sort_order'])) { + $data['payment_alipay_cross_sort_order'] = $this->request->post['payment_alipay_cross_sort_order']; + } else { + $data['payment_alipay_cross_sort_order'] = $this->config->get('payment_alipay_cross_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/alipay_cross', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/alipay_cross')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_alipay_cross_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_alipay_cross_merchant_private_key']) { + $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/amazon_login_pay.php b/public/admin/controller/extension/payment/amazon_login_pay.php new file mode 100644 index 0000000..88abbda --- /dev/null +++ b/public/admin/controller/extension/payment/amazon_login_pay.php @@ -0,0 +1,590 @@ +<?php +class ControllerExtensionPaymentAmazonLoginPay extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/amazon_login_pay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/amazon_login_pay'); + + $this->model_extension_payment_amazon_login_pay->install(); + + $this->trimIntegrationDetails(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_amazon_login_pay', $this->request->post); + + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + $this->model_extension_payment_amazon_login_pay->addEvents(); + + $this->session->data['success'] = $this->language->get('text_success'); + + if (isset($this->request->post['language_reload'])) { + $this->response->redirect($this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_access_key'])) { + $data['error_access_key'] = $this->error['error_access_key']; + } else { + $data['error_access_key'] = ''; + } + + if (isset($this->error['error_access_secret'])) { + $data['error_access_secret'] = $this->error['error_access_secret']; + } else { + $data['error_access_secret'] = ''; + } + + if (isset($this->error['error_client_secret'])) { + $data['error_client_secret'] = $this->error['error_client_secret']; + } else { + $data['error_client_secret'] = ''; + } + + if (isset($this->error['error_client_id'])) { + $data['error_client_id'] = $this->error['error_client_id']; + } else { + $data['error_client_id'] = ''; + } + + if (isset($this->error['error_minimum_total'])) { + $data['error_minimum_total'] = $this->error['error_minimum_total']; + } else { + $data['error_minimum_total'] = ''; + } + + if (isset($this->error['error_curreny'])) { + $data['error_curreny'] = $this->error['error_curreny']; + } else { + $data['error_curreny'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['https_catalog'] = HTTPS_CATALOG; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_amazon_login_pay_merchant_id'])) { + $data['payment_amazon_login_pay_merchant_id'] = $this->request->post['payment_amazon_login_pay_merchant_id']; + } elseif ($this->config->get('payment_amazon_login_pay_merchant_id')) { + $data['payment_amazon_login_pay_merchant_id'] = $this->config->get('payment_amazon_login_pay_merchant_id'); + } else { + $data['payment_amazon_login_pay_merchant_id'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_access_key'])) { + $data['payment_amazon_login_pay_access_key'] = $this->request->post['payment_amazon_login_pay_access_key']; + } elseif ($this->config->get('payment_amazon_login_pay_access_key')) { + $data['payment_amazon_login_pay_access_key'] = $this->config->get('payment_amazon_login_pay_access_key'); + } else { + $data['payment_amazon_login_pay_access_key'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_access_secret'])) { + $data['payment_amazon_login_pay_access_secret'] = $this->request->post['payment_amazon_login_pay_access_secret']; + } elseif ($this->config->get('payment_amazon_login_pay_access_secret')) { + $data['payment_amazon_login_pay_access_secret'] = $this->config->get('payment_amazon_login_pay_access_secret'); + } else { + $data['payment_amazon_login_pay_access_secret'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_client_id'])) { + $data['payment_amazon_login_pay_client_id'] = $this->request->post['payment_amazon_login_pay_client_id']; + } elseif ($this->config->get('payment_amazon_login_pay_client_id')) { + $data['payment_amazon_login_pay_client_id'] = $this->config->get('payment_amazon_login_pay_client_id'); + } else { + $data['payment_amazon_login_pay_client_id'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_client_secret'])) { + $data['payment_amazon_login_pay_client_secret'] = $this->request->post['payment_amazon_login_pay_client_secret']; + } elseif ($this->config->get('payment_amazon_login_pay_client_secret')) { + $data['payment_amazon_login_pay_client_secret'] = $this->config->get('payment_amazon_login_pay_client_secret'); + } else { + $data['payment_amazon_login_pay_client_secret'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_test'])) { + $data['payment_amazon_login_pay_test'] = $this->request->post['payment_amazon_login_pay_test']; + } elseif ($this->config->get('payment_amazon_login_pay_test')) { + $data['payment_amazon_login_pay_test'] = $this->config->get('payment_amazon_login_pay_test'); + } else { + $data['payment_amazon_login_pay_test'] = 'sandbox'; + } + + if (isset($this->request->post['payment_amazon_login_pay_mode'])) { + $data['payment_amazon_login_pay_mode'] = $this->request->post['payment_amazon_login_pay_mode']; + } elseif ($this->config->get('payment_amazon_login_pay_mode')) { + $data['payment_amazon_login_pay_mode'] = $this->config->get('payment_amazon_login_pay_mode'); + } else { + $data['payment_amazon_login_pay_mode'] = 'payment'; + } + + if (isset($this->request->post['payment_amazon_login_pay_checkout'])) { + $data['payment_amazon_login_pay_checkout'] = $this->request->post['payment_amazon_login_pay_checkout']; + } elseif ($this->config->get('payment_amazon_login_pay_checkout')) { + $data['payment_amazon_login_pay_checkout'] = $this->config->get('payment_amazon_login_pay_checkout'); + } else { + $data['payment_amazon_login_pay_checkout'] = 'payment'; + } + + if (isset($this->request->post['payment_amazon_login_pay_payment_region'])) { + $data['payment_amazon_login_pay_payment_region'] = $this->request->post['payment_amazon_login_pay_payment_region']; + } elseif ($this->config->get('payment_amazon_login_pay_payment_region')) { + $data['payment_amazon_login_pay_payment_region'] = $this->config->get('payment_amazon_login_pay_payment_region'); + } elseif (in_array($this->config->get('config_currency'), array('EUR', 'GBP', 'USD'))) { + $data['payment_amazon_login_pay_payment_region'] = $this->config->get('config_currency'); + } else { + $data['payment_amazon_login_pay_payment_region'] = 'USD'; + } + + if ($data['payment_amazon_login_pay_payment_region'] == 'EUR') { + $data['payment_amazon_login_pay_language'] = 'de-DE'; + $data['sp_id'] = 'AW93DIZMWSDWS'; + $data['locale'] = 'EUR'; + $ld = 'AW93DIZMWSDWS'; + } elseif ($data['payment_amazon_login_pay_payment_region'] == 'GBP') { + $data['payment_amazon_login_pay_language'] = 'en-GB'; + $data['sp_id'] = 'AW93DIZMWSDWS'; + $data['locale'] = 'GBP'; + $ld = 'AW93DIZMWSDWS'; + } else { + $data['payment_amazon_login_pay_language'] = 'en-US'; + $data['sp_id'] = 'A3GK1RS09H3A7D'; + $data['locale'] = 'US'; + $ld = 'A3GK1RS09H3A7D'; + } + + if (isset($this->request->post['payment_amazon_login_pay_language'])) { + $data['payment_amazon_login_pay_language'] = $this->request->post['payment_amazon_login_pay_language']; + } elseif ($this->config->get('payment_amazon_login_pay_language')) { + $data['payment_amazon_login_pay_language'] = $this->config->get('payment_amazon_login_pay_language'); + } + + if (isset($this->request->post['payment_amazon_login_pay_capture_status'])) { + $data['payment_amazon_login_pay_capture_status'] = $this->request->post['payment_amazon_login_pay_capture_status']; + } elseif ($this->config->get('payment_amazon_login_pay_capture_status')) { + $data['payment_amazon_login_pay_capture_status'] = $this->config->get('payment_amazon_login_pay_capture_status'); + } else { + $data['payment_amazon_login_pay_capture_status'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_pending_status'])) { + $data['payment_amazon_login_pay_pending_status'] = $this->request->post['payment_amazon_login_pay_pending_status']; + } elseif ($this->config->get('payment_amazon_login_pay_pending_status')) { + $data['payment_amazon_login_pay_pending_status'] = $this->config->get('payment_amazon_login_pay_pending_status'); + } else { + $data['payment_amazon_login_pay_pending_status'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_ipn_token'])) { + $data['payment_amazon_login_pay_ipn_token'] = $this->request->post['payment_amazon_login_pay_ipn_token']; + } elseif ($this->config->get('payment_amazon_login_pay_ipn_token')) { + $data['payment_amazon_login_pay_ipn_token'] = $this->config->get('payment_amazon_login_pay_ipn_token'); + } else { + $data['payment_amazon_login_pay_ipn_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/amazon_login_pay/ipn&token=' . $data['payment_amazon_login_pay_ipn_token']; + + if (isset($this->request->post['payment_amazon_login_pay_minimum_total'])) { + $data['payment_amazon_login_pay_minimum_total'] = $this->request->post['payment_amazon_login_pay_minimum_total']; + } elseif ($this->config->get('payment_amazon_login_pay_minimum_total')) { + $data['payment_amazon_login_pay_minimum_total'] = $this->config->get('payment_amazon_login_pay_minimum_total'); + } else { + $data['payment_amazon_login_pay_minimum_total'] = '0.01'; + } + + if (isset($this->request->post['payment_amazon_login_pay_geo_zone'])) { + $data['payment_amazon_login_pay_geo_zone'] = $this->request->post['payment_amazon_login_pay_geo_zone']; + } elseif ($this->config->get('payment_amazon_login_pay_geo_zone')) { + $data['payment_amazon_login_pay_geo_zone'] = $this->config->get('payment_amazon_login_pay_geo_zone'); + } else { + $data['payment_amazon_login_pay_geo_zone'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_debug'])) { + $data['payment_amazon_login_pay_debug'] = $this->request->post['payment_amazon_login_pay_debug']; + } elseif ($this->config->get('payment_amazon_login_pay_debug')) { + $data['payment_amazon_login_pay_debug'] = $this->config->get('payment_amazon_login_pay_debug'); + } else { + $data['payment_amazon_login_pay_debug'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_sort_order'])) { + $data['payment_amazon_login_pay_sort_order'] = $this->request->post['payment_amazon_login_pay_sort_order']; + } elseif ($this->config->get('payment_amazon_login_pay_sort_order')) { + $data['payment_amazon_login_pay_sort_order'] = $this->config->get('payment_amazon_login_pay_sort_order'); + } else { + $data['payment_amazon_login_pay_sort_order'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_status'])) { + $data['payment_amazon_login_pay_status'] = $this->request->post['payment_amazon_login_pay_status']; + } elseif ($this->config->get('payment_amazon_login_pay_status')) { + $data['payment_amazon_login_pay_status'] = $this->config->get('payment_amazon_login_pay_status'); + } else { + $data['payment_amazon_login_pay_status'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_declined_code'])) { + $data['payment_amazon_login_pay_declined_code'] = $this->request->post['payment_amazon_login_pay_declined_code']; + } elseif ($this->config->get('payment_amazon_login_pay_declined_code')) { + $data['payment_amazon_login_pay_declined_code'] = $this->config->get('payment_amazon_login_pay_declined_code'); + } else { + $data['payment_amazon_login_pay_declined_code'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['declined_codes'] = array($this->language->get('text_amazon_invalid'), $this->language->get('text_amazon_rejected'), $this->language->get('text_amazon_timeout')); + + $data['unique_id'] = 'oc-' . str_replace(' ', '-', strtolower($this->config->get('config_name'))) . '_' . mt_rand(); + $data['allowed_login_domain'] = html_entity_decode(HTTPS_CATALOG); + $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_login/login'; + $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_pay/login'; + $data['store_name'] = $this->config->get('config_name'); + $data['simple_path_language'] = str_replace('-', '_', $data['payment_amazon_login_pay_language']); + + if ($data['payment_amazon_login_pay_payment_region'] == 'USD') { + $data['registration_url'] = "https://payments.amazon.com/register?registration_source=SPPL&spId=" . $ld; + + $data['languages'] = array( + 'en-US' => $this->language->get('text_us') + ); + } else { + $data['registration_url'] = "https://payments-eu.amazon.com/register?registration_source=SPPL&spId=" . $ld; + + $data['languages'] = array( + 'de-DE' => $this->language->get('text_de'), + 'es-ES' => $this->language->get('text_es'), + 'fr-FR' => $this->language->get('text_fr'), + 'it-IT' => $this->language->get('text_it'), + 'en-GB' => $this->language->get('text_uk') + ); + } + + $data['payment_regions'] = array( + 'EUR' => $this->language->get('text_eu_region'), + 'GBP' => $this->language->get('text_uk_region'), + 'USD' => $this->language->get('text_us_region') + ); + + $data['has_ssl'] = !empty($this->request->server['HTTPS']); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/amazon_login_pay', $data)); + } + + public function install() { + $this->load->model('extension/payment/amazon_login_pay'); + $this->model_extension_payment_amazon_login_pay->install(); + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + $this->model_extension_payment_amazon_login_pay->addEvents(); + } + + public function uninstall() { + $this->load->model('extension/payment/amazon_login_pay'); + $this->load->model('setting/event'); + $this->model_extension_payment_amazon_login_pay->uninstall(); + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + } + + public function order() { + + if ($this->config->get('payment_amazon_login_pay_status')) { + + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->get['order_id']); + + if (!empty($amazon_login_pay_order)) { + + $this->load->language('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order['total_captured'] = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + $amazon_login_pay_order['total_formatted'] = $this->currency->format($amazon_login_pay_order['total'], $amazon_login_pay_order['currency_code'], true, true); + $amazon_login_pay_order['total_captured_formatted'] = $this->currency->format($amazon_login_pay_order['total_captured'], $amazon_login_pay_order['currency_code'], true, true); + + $data['amazon_login_pay_order'] = $amazon_login_pay_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/amazon_login_pay_order', $data); + } + } + } + + public function cancel() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $cancel_response = $this->model_extension_payment_amazon_login_pay->cancel($amazon_login_pay_order); + + $this->model_extension_payment_amazon_login_pay->logger($cancel_response); + + if ($cancel_response['status'] == 'Completed') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'cancel', $cancel_response['status'], 0.00); + $this->model_extension_payment_amazon_login_pay->updateCancelStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $json['msg'] = $this->language->get('text_cancel_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['type'] = 'cancel'; + $json['data']['status'] = $cancel_response['status']; + $json['data']['amount'] = $this->currency->format(0.00, $amazon_login_pay_order['currency_code'], true, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($cancel_response['StatuesDetail']) && !empty($cancel_response['StatuesDetail']) ? (string)$cancel_response['StatuesDetail'] : 'Unable to cancel'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_amazon_login_pay->capture($amazon_login_pay_order, $this->request->post['amount']); + $this->model_extension_payment_amazon_login_pay->logger($capture_response); + + if ($capture_response['status'] == 'Completed' || $capture_response['status'] == 'Pending') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'capture', $capture_response['status'], $this->request->post['amount'], $capture_response['AmazonAuthorizationId'], $capture_response['AmazonCaptureId']); + + $this->model_extension_payment_amazon_login_pay->updateAuthorizationStatus($capture_response['AmazonAuthorizationId'], 'Closed'); + + $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + if ($total_captured > 0) { + $order_reference_id = $amazon_login_pay_order['amazon_order_reference_id']; + + if ($this->model_extension_payment_amazon_login_pay->isOrderInState($order_reference_id, array('Open', 'Suspended'))) { + $this->model_extension_payment_amazon_login_pay->closeOrderRef($order_reference_id); + } + } + + if ($total_captured >= (double)$amazon_login_pay_order['total']) { + $this->model_extension_payment_amazon_login_pay->updateCaptureStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['type'] = 'capture'; + $json['data']['status'] = $capture_response['status']; + $json['data']['amazon_authorization_id'] = $capture_response['AmazonAuthorizationId']; + $json['data']['amazon_capture_id'] = $capture_response['AmazonCaptureId']; + $json['data']['amount'] = $this->currency->format($this->request->post['amount'], $amazon_login_pay_order['currency_code'], true, true); + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response['status_detail']) && !empty($capture_response['status_detail']) ? (string)$capture_response['status_detail'] : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_amazon_login_pay->refund($amazon_login_pay_order, $this->request->post['amount']); + + $this->model_extension_payment_amazon_login_pay->logger($refund_response); + + $refund_status = ''; + $total_captured = ''; + $total_refunded = ''; + + foreach ($refund_response as $response) { + if ($response['status'] == 'Pending') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'refund', $response['status'], $response['amount'] * -1, $response['amazon_authorization_id'], $response['amazon_capture_id'], $response['AmazonRefundId']); + + $total_refunded = $this->model_extension_payment_amazon_login_pay->getTotalRefunded($amazon_login_pay_order['amazon_login_pay_order_id']); + $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + if ($total_captured <= 0 && $amazon_login_pay_order['capture_status'] == 1) { + $this->model_extension_payment_amazon_login_pay->updateRefundStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $refund_status = 1; + $json['msg'][] = $this->language->get('text_refund_ok_order') . '<br />'; + } else { + $refund_status = 0; + $json['msg'][] = $this->language->get('text_refund_ok') . '<br />'; + } + + $data = array(); + $data['date_added'] = date("Y-m-d H:i:s"); + $data['type'] = 'refund'; + $data['status'] = $response['status']; + $data['amazon_authorization_id'] = $response['amazon_authorization_id']; + $data['amazon_capture_id'] = $response['amazon_capture_id']; + $data['amazon_refund_id'] = $response['AmazonRefundId']; + $data['amount'] = $this->currency->format(($response['amount'] * -1), $amazon_login_pay_order['currency_code'], true, true); + $json['data'][] = $data; + } else { + $json['error'] = true; + $json['error_msg'][] = isset($response['status_detail']) && !empty($response['status_detail']) ? (string)$response['status_detail'] : 'Unable to refund'; + } + } + $json['refund_status'] = $refund_status; + $json['total_captured'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true); + $json['total_refunded'] = $this->currency->format($total_refunded, $amazon_login_pay_order['currency_code'], true, true); + } else { + $json['error'] = true; + $json['error_msg'][] = $this->language->get('error_data_missing'); + } + $this->response->setOutput(json_encode($json)); + } + + protected function trimIntegrationDetails() { + $integration_keys = array( + 'payment_amazon_login_pay_merchant_id', + 'payment_amazon_login_pay_access_key', + 'payment_amazon_login_pay_access_secret', + 'payment_amazon_login_pay_client_id', + 'payment_amazon_login_pay_client_secret' + ); + + foreach ($this->request->post as $key => $value) { + if (in_array($key, $integration_keys)) { + $this->request->post[$key] = trim($value); + } + } + } + + protected function validate() { + $this->load->model('localisation/currency'); + + if (!$this->user->hasPermission('modify', 'extension/payment/amazon_login_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_amazon_login_pay_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_amazon_login_pay_access_key']) { + $this->error['error_access_key'] = $this->language->get('error_access_key'); + } + + if (empty($this->error)) { + $this->load->model('extension/payment/amazon_login_pay'); + $errors = $this->model_extension_payment_amazon_login_pay->validateDetails($this->request->post); + if (isset($errors['error_code']) && $errors['error_code'] == 'InvalidParameterValue') { + $this->error['error_merchant_id'] = $errors['status_detail']; + } elseif (isset($errors['error_code']) && $errors['error_code'] == 'InvalidAccessKeyId') { + $this->error['error_access_key'] = $errors['status_detail']; + } + } + + if (!$this->request->post['payment_amazon_login_pay_access_secret']) { + $this->error['error_access_secret'] = $this->language->get('error_access_secret'); + } + + if (!$this->request->post['payment_amazon_login_pay_client_id']) { + $this->error['error_client_id'] = $this->language->get('error_client_id'); + } + + if (!$this->request->post['payment_amazon_login_pay_client_secret']) { + $this->error['error_client_secret'] = $this->language->get('error_client_secret'); + } + + if ($this->request->post['payment_amazon_login_pay_minimum_total'] <= 0) { + $this->error['error_minimum_total'] = $this->language->get('error_minimum_total'); + } + + if (isset($this->request->post['amazon_login_pay_region'])) { + $currency_code = $this->request->post['amazon_login_pay_region']; + + $currency = $this->model_localisation_currency->getCurrency($this->currency->getId($currency_code)); + + if (empty($currency) || $currency['status'] != '1') { + $this->error['error_curreny'] = sprintf($this->language->get('error_curreny'), $currency_code); + } + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/authorizenet_aim.php b/public/admin/controller/extension/payment/authorizenet_aim.php new file mode 100644 index 0000000..517fc4e --- /dev/null +++ b/public/admin/controller/extension/payment/authorizenet_aim.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionPaymentAuthorizenetAim extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/authorizenet_aim'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_authorizenet_aim', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['login'])) { + $data['error_login'] = $this->error['login']; + } else { + $data['error_login'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/authorizenet_aim', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/authorizenet_aim', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_authorizenet_aim_login'])) { + $data['payment_authorizenet_aim_login'] = $this->request->post['payment_authorizenet_aim_login']; + } else { + $data['payment_authorizenet_aim_login'] = $this->config->get('payment_authorizenet_aim_login'); + } + + if (isset($this->request->post['payment_authorizenet_aim_key'])) { + $data['payment_authorizenet_aim_key'] = $this->request->post['payment_authorizenet_aim_key']; + } else { + $data['payment_authorizenet_aim_key'] = $this->config->get('payment_authorizenet_aim_key'); + } + + if (isset($this->request->post['payment_authorizenet_aim_hash'])) { + $data['payment_authorizenet_aim_hash'] = $this->request->post['payment_authorizenet_aim_hash']; + } else { + $data['payment_authorizenet_aim_hash'] = $this->config->get('payment_authorizenet_aim_hash'); + } + + if (isset($this->request->post['payment_authorizenet_aim_server'])) { + $data['payment_authorizenet_aim_server'] = $this->request->post['payment_authorizenet_aim_server']; + } else { + $data['payment_authorizenet_aim_server'] = $this->config->get('payment_authorizenet_aim_server'); + } + + if (isset($this->request->post['payment_authorizenet_aim_mode'])) { + $data['payment_authorizenet_aim_mode'] = $this->request->post['payment_authorizenet_aim_mode']; + } else { + $data['payment_authorizenet_aim_mode'] = $this->config->get('payment_authorizenet_aim_mode'); + } + + if (isset($this->request->post['payment_authorizenet_aim_method'])) { + $data['payment_authorizenet_aim_method'] = $this->request->post['payment_authorizenet_aim_method']; + } else { + $data['payment_authorizenet_aim_method'] = $this->config->get('payment_authorizenet_aim_method'); + } + + if (isset($this->request->post['payment_authorizenet_aim_total'])) { + $data['payment_authorizenet_aim_total'] = $this->request->post['payment_authorizenet_aim_total']; + } else { + $data['payment_authorizenet_aim_total'] = $this->config->get('payment_authorizenet_aim_total'); + } + + if (isset($this->request->post['payment_authorizenet_aim_order_status_id'])) { + $data['payment_authorizenet_aim_order_status_id'] = $this->request->post['payment_authorizenet_aim_order_status_id']; + } else { + $data['payment_authorizenet_aim_order_status_id'] = $this->config->get('payment_authorizenet_aim_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_authorizenet_aim_geo_zone_id'])) { + $data['payment_authorizenet_aim_geo_zone_id'] = $this->request->post['payment_authorizenet_aim_geo_zone_id']; + } else { + $data['payment_authorizenet_aim_geo_zone_id'] = $this->config->get('payment_authorizenet_aim_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_authorizenet_aim_status'])) { + $data['payment_authorizenet_aim_status'] = $this->request->post['payment_authorizenet_aim_status']; + } else { + $data['payment_authorizenet_aim_status'] = $this->config->get('payment_authorizenet_aim_status'); + } + + if (isset($this->request->post['payment_authorizenet_aim_sort_order'])) { + $data['payment_authorizenet_aim_sort_order'] = $this->request->post['payment_authorizenet_aim_sort_order']; + } else { + $data['payment_authorizenet_aim_sort_order'] = $this->config->get('payment_authorizenet_aim_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/authorizenet_aim', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_aim')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_authorizenet_aim_login']) { + $this->error['login'] = $this->language->get('error_login'); + } + + if (!$this->request->post['payment_authorizenet_aim_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/authorizenet_sim.php b/public/admin/controller/extension/payment/authorizenet_sim.php new file mode 100644 index 0000000..ceb4dbe --- /dev/null +++ b/public/admin/controller/extension/payment/authorizenet_sim.php @@ -0,0 +1,145 @@ +<?php +class ControllerExtensionPaymentAuthorizeNetSim extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/authorizenet_sim'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_authorizenet_sim', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/authorizenet_sim', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/authorizenet_sim', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_authorizenet_sim_merchant'])) { + $data['payment_authorizenet_sim_merchant'] = $this->request->post['payment_authorizenet_sim_merchant']; + } else { + $data['payment_authorizenet_sim_merchant'] = $this->config->get('payment_authorizenet_sim_merchant'); + } + + if (isset($this->request->post['payment_authorizenet_sim_key'])) { + $data['payment_authorizenet_sim_key'] = $this->request->post['payment_authorizenet_sim_key']; + } else { + $data['payment_authorizenet_sim_key'] = $this->config->get('payment_authorizenet_sim_key'); + } + + if (isset($this->request->post['payment_authorizenet_sim_test'])) { + $data['payment_authorizenet_sim_test'] = $this->request->post['payment_authorizenet_sim_test']; + } else { + $data['payment_authorizenet_sim_test'] = $this->config->get('payment_authorizenet_sim_test'); + } + + $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/authorizenet_sim/callback'; + + if (isset($this->request->post['payment_authorizenet_sim_hash'])) { + $data['payment_authorizenet_sim_hash'] = $this->request->post['payment_authorizenet_sim_hash']; + } else { + $data['payment_authorizenet_sim_hash'] = $this->config->get('payment_authorizenet_sim_hash'); + } + + if (isset($this->request->post['payment_authorizenet_sim_total'])) { + $data['payment_authorizenet_sim_total'] = $this->request->post['payment_authorizenet_sim_total']; + } else { + $data['payment_authorizenet_sim_total'] = $this->config->get('payment_authorizenet_sim_total'); + } + + if (isset($this->request->post['payment_authorizenet_sim_order_status_id'])) { + $data['payment_authorizenet_sim_order_status_id'] = $this->request->post['payment_authorizenet_sim_order_status_id']; + } else { + $data['payment_authorizenet_sim_order_status_id'] = $this->config->get('payment_authorizenet_sim_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_authorizenet_sim_geo_zone_id'])) { + $data['payment_authorizenet_sim_geo_zone_id'] = $this->request->post['payment_authorizenet_sim_geo_zone_id']; + } else { + $data['payment_authorizenet_sim_geo_zone_id'] = $this->config->get('payment_authorizenet_sim_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_authorizenet_sim_status'])) { + $data['payment_authorizenet_sim_status'] = $this->request->post['payment_authorizenet_sim_status']; + } else { + $data['payment_authorizenet_sim_status'] = $this->config->get('payment_authorizenet_sim_status'); + } + + if (isset($this->request->post['payment_authorizenet_sim_sort_order'])) { + $data['payment_authorizenet_sim_sort_order'] = $this->request->post['payment_authorizenet_sim_sort_order']; + } else { + $data['payment_authorizenet_sim_sort_order'] = $this->config->get('payment_authorizenet_sim_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/authorizenet_sim', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_sim')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_authorizenet_sim_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_authorizenet_sim_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/bank_transfer.php b/public/admin/controller/extension/payment/bank_transfer.php new file mode 100644 index 0000000..9bb4882 --- /dev/null +++ b/public/admin/controller/extension/payment/bank_transfer.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionPaymentBankTransfer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/bank_transfer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bank_transfer', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['bank'])) { + $data['error_bank'] = $this->error['bank']; + } else { + $data['error_bank'] = array(); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bank_transfer', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bank_transfer', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $this->load->model('localisation/language'); + + $data['payment_bank_transfer'] = array(); + + $languages = $this->model_localisation_language->getLanguages(); + + foreach ($languages as $language) { + if (isset($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) { + $data['payment_bank_transfer_bank'][$language['language_id']] = $this->request->post['payment_bank_transfer_bank' . $language['language_id']]; + } else { + $data['payment_bank_transfer_bank'][$language['language_id']] = $this->config->get('payment_bank_transfer_bank' . $language['language_id']); + } + } + + $data['languages'] = $languages; + + if (isset($this->request->post['payment_bank_transfer_total'])) { + $data['payment_bank_transfer_total'] = $this->request->post['payment_bank_transfer_total']; + } else { + $data['payment_bank_transfer_total'] = $this->config->get('payment_bank_transfer_total'); + } + + if (isset($this->request->post['payment_bank_transfer_order_status_id'])) { + $data['payment_bank_transfer_order_status_id'] = $this->request->post['payment_bank_transfer_order_status_id']; + } else { + $data['payment_bank_transfer_order_status_id'] = $this->config->get('payment_bank_transfer_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bank_transfer_geo_zone_id'])) { + $data['payment_bank_transfer_geo_zone_id'] = $this->request->post['payment_bank_transfer_geo_zone_id']; + } else { + $data['payment_bank_transfer_geo_zone_id'] = $this->config->get('payment_bank_transfer_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bank_transfer_status'])) { + $data['payment_bank_transfer_status'] = $this->request->post['payment_bank_transfer_status']; + } else { + $data['payment_bank_transfer_status'] = $this->config->get('payment_bank_transfer_status'); + } + + if (isset($this->request->post['payment_bank_transfer_sort_order'])) { + $data['payment_bank_transfer_sort_order'] = $this->request->post['payment_bank_transfer_sort_order']; + } else { + $data['payment_bank_transfer_sort_order'] = $this->config->get('payment_bank_transfer_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bank_transfer', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bank_transfer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/language'); + + $languages = $this->model_localisation_language->getLanguages(); + + foreach ($languages as $language) { + if (empty($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) { + $this->error['bank'][$language['language_id']] = $this->language->get('error_bank'); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/bluepay_hosted.php b/public/admin/controller/extension/payment/bluepay_hosted.php new file mode 100644 index 0000000..2ce59d6 --- /dev/null +++ b/public/admin/controller/extension/payment/bluepay_hosted.php @@ -0,0 +1,351 @@ +<?php +class ControllerExtensionPaymentBluePayHosted extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/bluepay_hosted'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bluepay_hosted', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account_name'])) { + $data['error_account_name'] = $this->error['account_name']; + } else { + $data['error_account_name'] = ''; + } + + if (isset($this->error['account_id'])) { + $data['error_account_id'] = $this->error['account_id']; + } else { + $data['error_account_id'] = ''; + } + + if (isset($this->error['secret_key'])) { + $data['error_secret_key'] = $this->error['secret_key']; + } else { + $data['error_secret_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bluepay_hosted', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bluepay_hosted', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_bluepay_hosted_account_name'])) { + $data['payment_bluepay_hosted_account_name'] = $this->request->post['payment_bluepay_hosted_account_name']; + } else { + $data['payment_bluepay_hosted_account_name'] = $this->config->get('payment_bluepay_hosted_account_name'); + } + + if (isset($this->request->post['payment_bluepay_hosted_account_id'])) { + $data['payment_bluepay_hosted_account_id'] = $this->request->post['payment_bluepay_hosted_account_id']; + } else { + $data['payment_bluepay_hosted_account_id'] = $this->config->get('payment_bluepay_hosted_account_id'); + } + + if (isset($this->request->post['payment_bluepay_hosted_secret_key'])) { + $data['payment_bluepay_hosted_secret_key'] = $this->request->post['payment_bluepay_hosted_secret_key']; + } else { + $data['payment_bluepay_hosted_secret_key'] = $this->config->get('payment_bluepay_hosted_secret_key'); + } + + if (isset($this->request->post['payment_bluepay_hosted_test'])) { + $data['payment_bluepay_hosted_test'] = $this->request->post['payment_bluepay_hosted_test']; + } else { + $data['payment_bluepay_hosted_test'] = $this->config->get('payment_bluepay_hosted_test'); + } + + if (isset($this->request->post['payment_bluepay_hosted_transaction'])) { + $data['payment_bluepay_hosted_transaction'] = $this->request->post['payment_bluepay_hosted_transaction']; + } else { + $data['payment_bluepay_hosted_transaction'] = $this->config->get('payment_bluepay_hosted_transaction'); + } + + if (isset($this->request->post['payment_bluepay_hosted_amex'])) { + $data['payment_bluepay_hosted_amex'] = $this->request->post['payment_bluepay_hosted_amex']; + } else { + $data['payment_bluepay_hosted_amex'] = $this->config->get('payment_bluepay_hosted_amex'); + } + + if (isset($this->request->post['payment_bluepay_hosted_discover'])) { + $data['payment_bluepay_hosted_discover'] = $this->request->post['payment_bluepay_hosted_discover']; + } else { + $data['payment_bluepay_hosted_discover'] = $this->config->get('payment_bluepay_hosted_discover'); + } + + if (isset($this->request->post['payment_bluepay_hosted_total'])) { + $data['payment_bluepay_hosted_total'] = $this->request->post['payment_bluepay_hosted_total']; + } else { + $data['payment_bluepay_hosted_total'] = $this->config->get('payment_bluepay_hosted_total'); + } + + if (isset($this->request->post['payment_bluepay_hosted_order_status_id'])) { + $data['payment_bluepay_hosted_order_status_id'] = $this->request->post['payment_bluepay_hosted_order_status_id']; + } elseif ($this->config->get('payment_bluepay_hosted_order_status_id')) { + $data['payment_bluepay_hosted_order_status_id'] = $this->config->get('payment_bluepay_hosted_order_status_id'); + } else { + $data['payment_bluepay_hosted_order_status_id'] = 2; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bluepay_hosted_geo_zone_id'])) { + $data['payment_bluepay_hosted_geo_zone_id'] = $this->request->post['payment_bluepay_hosted_geo_zone_id']; + } else { + $data['payment_bluepay_hosted_geo_zone_id'] = $this->config->get('payment_bluepay_hosted_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bluepay_hosted_status'])) { + $data['payment_bluepay_hosted_status'] = $this->request->post['payment_bluepay_hosted_status']; + } else { + $data['payment_bluepay_hosted_status'] = $this->config->get('payment_bluepay_hosted_status'); + } + + if (isset($this->request->post['payment_bluepay_hosted_debug'])) { + $data['payment_bluepay_hosted_debug'] = $this->request->post['payment_bluepay_hosted_debug']; + } else { + $data['payment_bluepay_hosted_debug'] = $this->config->get('payment_bluepay_hosted_debug'); + } + + if (isset($this->request->post['payment_bluepay_hosted_sort_order'])) { + $data['payment_bluepay_hosted_sort_order'] = $this->request->post['payment_bluepay_hosted_sort_order']; + } else { + $data['payment_bluepay_hosted_sort_order'] = $this->config->get('payment_bluepay_hosted_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bluepay_hosted', $data)); + } + + public function install() { + $this->load->model('extension/payment/bluepay_hosted'); + + $this->model_extension_payment_bluepay_hosted->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/bluepay_hosted'); + + $this->model_extension_payment_bluepay_hosted->uninstall(); + } + + public function order() { + if ($this->config->get('payment_bluepay_hosted_status')) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->get['order_id']); + + if (!empty($bluepay_hosted_order)) { + $this->load->language('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order['total_released'] = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + $bluepay_hosted_order['total_formatted'] = $this->currency->format($bluepay_hosted_order['total'], $bluepay_hosted_order['currency_code'], false, false); + $bluepay_hosted_order['total_released_formatted'] = $this->currency->format($bluepay_hosted_order['total_released'], $bluepay_hosted_order['currency_code'], false, false); + + $data['bluepay_hosted_order'] = $bluepay_hosted_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/bluepay_hosted_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_bluepay_hosted->void($this->request->post['order_id']); + + $this->model_extension_payment_bluepay_hosted->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'void', $bluepay_hosted_order['total']); + $this->model_extension_payment_bluepay_hosted->updateVoidStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['total'] = $bluepay_hosted_order['total']; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_bluepay_hosted->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'payment', $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->updateTransactionId($bluepay_hosted_order['bluepay_hosted_order_id'], $release_response['RRNO']); + + $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + if ($total_released >= $bluepay_hosted_order['total']) { + $this->model_extension_payment_bluepay_hosted->updateReleaseStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_bluepay_hosted->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_bluepay_hosted->getTotalRebated($bluepay_hosted_order['bluepay_hosted_order_id']); + $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + if ($total_released <= 0 && $bluepay_hosted_order['release_status'] == 1) { + $this->model_extension_payment_bluepay_hosted->updateRebateStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_hosted')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_bluepay_hosted_account_name']) { + $this->error['account_name'] = $this->language->get('error_account_name'); + } + + if (!$this->request->post['payment_bluepay_hosted_account_id']) { + $this->error['account_id'] = $this->language->get('error_account_id'); + } + + if (!$this->request->post['payment_bluepay_hosted_secret_key']) { + $this->error['secret_key'] = $this->language->get('error_secret_key'); + } + + return !$this->error; + } + + public function callback() { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($this->request->get)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/bluepay_redirect.php b/public/admin/controller/extension/payment/bluepay_redirect.php new file mode 100644 index 0000000..a416a54 --- /dev/null +++ b/public/admin/controller/extension/payment/bluepay_redirect.php @@ -0,0 +1,331 @@ +<?php +class ControllerExtensionPaymentBluepayredirect extends Controller { + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/bluepay_redirect'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bluepay_redirect', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account_id'])) { + $data['error_account_id'] = $this->error['account_id']; + } else { + $data['error_account_id'] = ''; + } + + if (isset($this->error['secret_key'])) { + $data['error_secret_key'] = $this->error['secret_key']; + } else { + $data['error_secret_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bluepay_redirect', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bluepay_redirect', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_bluepay_redirect_account_id'])) { + $data['payment_bluepay_redirect_account_id'] = $this->request->post['payment_bluepay_redirect_account_id']; + } else { + $data['payment_bluepay_redirect_account_id'] = $this->config->get('payment_bluepay_redirect_account_id'); + } + + if (isset($this->request->post['payment_bluepay_redirect_secret_key'])) { + $data['payment_bluepay_redirect_secret_key'] = $this->request->post['payment_bluepay_redirect_secret_key']; + } else { + $data['payment_bluepay_redirect_secret_key'] = $this->config->get('payment_bluepay_redirect_secret_key'); + } + + if (isset($this->request->post['payment_bluepay_redirect_test'])) { + $data['payment_bluepay_redirect_test'] = $this->request->post['payment_bluepay_redirect_test']; + } else { + $data['payment_bluepay_redirect_test'] = $this->config->get('payment_bluepay_redirect_test'); + } + + if (isset($this->request->post['payment_bluepay_redirect_transaction'])) { + $data['payment_bluepay_redirect_transaction'] = $this->request->post['payment_bluepay_redirect_transaction']; + } else { + $data['payment_bluepay_redirect_transaction'] = $this->config->get('payment_bluepay_redirect_transaction'); + } + + if (isset($this->request->post['payment_bluepay_redirect_total'])) { + $data['payment_bluepay_redirect_total'] = $this->request->post['payment_bluepay_redirect_total']; + } else { + $data['payment_bluepay_redirect_total'] = $this->config->get('payment_bluepay_redirect_total'); + } + + if (isset($this->request->post['payment_bluepay_redirect_card'])) { + $data['payment_bluepay_redirect_card'] = $this->request->post['payment_bluepay_redirect_card']; + } else { + $data['payment_bluepay_redirect_card'] = $this->config->get('payment_bluepay_redirect_card'); + } + + if (isset($this->request->post['payment_bluepay_redirect_order_status_id'])) { + $data['payment_bluepay_redirect_order_status_id'] = $this->request->post['payment_bluepay_redirect_order_status_id']; + } elseif ($this->config->get('payment_bluepay_redirect_order_status_id')) { + $data['payment_bluepay_redirect_order_status_id'] = $this->config->get('payment_bluepay_redirect_order_status_id'); + } else { + $data['payment_bluepay_redirect_order_status_id'] = 2; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bluepay_redirect_geo_zone_id'])) { + $data['payment_bluepay_redirect_geo_zone_id'] = $this->request->post['payment_bluepay_redirect_geo_zone_id']; + } else { + $data['payment_bluepay_redirect_geo_zone_id'] = $this->config->get('payment_bluepay_redirect_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bluepay_redirect_status'])) { + $data['payment_bluepay_redirect_status'] = $this->request->post['payment_bluepay_redirect_status']; + } else { + $data['payment_bluepay_redirect_status'] = $this->config->get('payment_bluepay_redirect_status'); + } + + if (isset($this->request->post['payment_bluepay_redirect_debug'])) { + $data['payment_bluepay_redirect_debug'] = $this->request->post['payment_bluepay_redirect_debug']; + } else { + $data['payment_bluepay_redirect_debug'] = $this->config->get('payment_bluepay_redirect_debug'); + } + + if (isset($this->request->post['payment_bluepay_redirect_sort_order'])) { + $data['payment_bluepay_redirect_sort_order'] = $this->request->post['payment_bluepay_redirect_sort_order']; + } else { + $data['payment_bluepay_redirect_sort_order'] = $this->config->get('payment_bluepay_redirect_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bluepay_redirect', $data)); + } + + public function install() { + $this->load->model('extension/payment/bluepay_redirect'); + + $this->model_extension_payment_bluepay_redirect->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/bluepay_redirect'); + + $this->model_extension_payment_bluepay_redirect->uninstall(); + } + + public function order() { + if ($this->config->get('payment_bluepay_redirect_status')) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->get['order_id']); + + if (!empty($bluepay_redirect_order)) { + $this->load->language('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order['total_released'] = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + $bluepay_redirect_order['total_formatted'] = $this->currency->format($bluepay_redirect_order['total'], $bluepay_redirect_order['currency_code'], false, false); + $bluepay_redirect_order['total_released_formatted'] = $this->currency->format($bluepay_redirect_order['total_released'], $bluepay_redirect_order['currency_code'], false, false); + + $data['bluepay_redirect_order'] = $bluepay_redirect_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/bluepay_redirect_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_bluepay_redirect->void($this->request->post['order_id']); + + $this->model_extension_payment_bluepay_redirect->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'void', $bluepay_redirect_order['total']); + $this->model_extension_payment_bluepay_redirect->updateVoidStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['total'] = $bluepay_redirect_order['total']; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_bluepay_redirect->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'payment', $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->updateTransactionId($bluepay_redirect_order['bluepay_redirect_order_id'], $release_response['RRNO']); + + $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + if ($total_released >= $bluepay_redirect_order['total']) { + $this->model_extension_payment_bluepay_redirect->updateReleaseStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_bluepay_redirect->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_bluepay_redirect->getTotalRebated($bluepay_redirect_order['bluepay_redirect_order_id']); + $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + if ($total_released <= 0 && $bluepay_redirect_order['release_status'] == 1) { + $this->model_extension_payment_bluepay_redirect->updateRebateStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_redirect')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_bluepay_redirect_account_id']) { + $this->error['account_id'] = $this->language->get('error_account_id'); + } + + if (!$this->request->post['payment_bluepay_redirect_secret_key']) { + $this->error['secret_key'] = $this->language->get('error_secret_key'); + } + + return !$this->error; + } + + public function callback() { + $this->response->addHeader('Content-Type: application/json'); + + $this->response->setOutput(json_encode($this->request->get)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cardconnect.php b/public/admin/controller/extension/payment/cardconnect.php new file mode 100644 index 0000000..8039cf4 --- /dev/null +++ b/public/admin/controller/extension/payment/cardconnect.php @@ -0,0 +1,501 @@ +<?php +class ControllerExtensionPaymentCardConnect extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/cardconnect'); + + $this->load->language('extension/payment/cardconnect'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cardconnect', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cardconnect', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cardconnect', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cardconnect_merchant_id'])) { + $data['payment_cardconnect_merchant_id'] = $this->request->post['payment_cardconnect_merchant_id']; + } else { + $data['payment_cardconnect_merchant_id'] = $this->config->get('payment_cardconnect_merchant_id'); + } + + if (isset($this->request->post['cardconnect_api_username'])) { + $data['cardconnect_api_username'] = $this->request->post['cardconnect_api_username']; + } else { + $data['cardconnect_api_username'] = $this->config->get('cardconnect_api_username'); + } + + if (isset($this->request->post['cardconnect_api_password'])) { + $data['cardconnect_api_password'] = $this->request->post['cardconnect_api_password']; + } else { + $data['cardconnect_api_password'] = $this->config->get('cardconnect_api_password'); + } + + if (isset($this->request->post['cardconnect_token'])) { + $data['cardconnect_token'] = $this->request->post['cardconnect_token']; + } elseif ($this->config->has('cardconnect_token')) { + $data['cardconnect_token'] = $this->config->get('cardconnect_token'); + } else { + $data['cardconnect_token'] = md5(time()); + } + + if (isset($this->request->post['cardconnect_transaction'])) { + $data['cardconnect_transaction'] = $this->request->post['cardconnect_transaction']; + } else { + $data['cardconnect_transaction'] = $this->config->get('cardconnect_transaction'); + } + + if (isset($this->request->post['cardconnect_site'])) { + $data['cardconnect_site'] = $this->request->post['cardconnect_site']; + } elseif ($this->config->has('cardconnect_site')) { + $data['cardconnect_site'] = $this->config->get('cardconnect_site'); + } else { + $data['cardconnect_site'] = 'fts'; + } + + if (isset($this->request->post['cardconnect_environment'])) { + $data['cardconnect_environment'] = $this->request->post['cardconnect_environment']; + } else { + $data['cardconnect_environment'] = $this->config->get('cardconnect_environment'); + } + + if (isset($this->request->post['cardconnect_store_cards'])) { + $data['cardconnect_store_cards'] = $this->request->post['cardconnect_store_cards']; + } else { + $data['cardconnect_store_cards'] = $this->config->get('cardconnect_store_cards'); + } + + if (isset($this->request->post['cardconnect_echeck'])) { + $data['cardconnect_echeck'] = $this->request->post['cardconnect_echeck']; + } else { + $data['cardconnect_echeck'] = $this->config->get('cardconnect_echeck'); + } + + if (isset($this->request->post['cardconnect_total'])) { + $data['cardconnect_total'] = $this->request->post['cardconnect_total']; + } else { + $data['cardconnect_total'] = $this->config->get('cardconnect_total'); + } + + if (isset($this->request->post['cardconnect_geo_zone'])) { + $data['cardconnect_geo_zone'] = $this->request->post['cardconnect_geo_zone']; + } else { + $data['cardconnect_geo_zone'] = $this->config->get('cardconnect_geo_zone'); + } + + if (isset($this->request->post['cardconnect_status'])) { + $data['cardconnect_status'] = $this->request->post['cardconnect_status']; + } else { + $data['cardconnect_status'] = $this->config->get('cardconnect_status'); + } + + if (isset($this->request->post['cardconnect_logging'])) { + $data['cardconnect_logging'] = $this->request->post['cardconnect_logging']; + } else { + $data['cardconnect_logging'] = $this->config->get('cardconnect_logging'); + } + + if (isset($this->request->post['cardconnect_sort_order'])) { + $data['cardconnect_sort_order'] = $this->request->post['cardconnect_sort_order']; + } else { + $data['cardconnect_sort_order'] = $this->config->get('cardconnect_sort_order'); + } + + $data['cardconnect_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/cardconnect/cron&token=' . $data['cardconnect_token']; + + if ($this->config->get('cardconnect_cron_time')) { + $data['cardconnect_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('cardconnect_cron_time'))); + } else { + $data['cardconnect_cron_time'] = $this->language->get('text_no_cron_time'); + } + + if (isset($this->request->post['cardconnect_order_status_id_pending'])) { + $data['cardconnect_order_status_id_pending'] = $this->request->post['cardconnect_order_status_id_pending']; + } elseif ($this->config->has('cardconnect_order_status_id_pending')) { + $data['cardconnect_order_status_id_pending'] = $this->config->get('cardconnect_order_status_id_pending'); + } else { + $data['cardconnect_order_status_id_pending'] = '1'; + } + + if (isset($this->request->post['cardconnect_order_status_id_processing'])) { + $data['cardconnect_order_status_id_processing'] = $this->request->post['cardconnect_order_status_id_processing']; + } elseif ($this->config->has('cardconnect_order_status_id_processing')) { + $data['cardconnect_order_status_id_processing'] = $this->config->get('cardconnect_order_status_id_processing'); + } else { + $data['cardconnect_order_status_id_processing'] = '2'; + } + + 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->error['payment_cardconnect_merchant_id'])) { + $data['error_payment_cardconnect_merchant_id'] = $this->error['payment_cardconnect_merchant_id']; + } else { + $data['error_payment_cardconnect_merchant_id'] = ''; + } + + if (isset($this->error['cardconnect_api_username'])) { + $data['error_cardconnect_api_username'] = $this->error['cardconnect_api_username']; + } else { + $data['error_cardconnect_api_username'] = ''; + } + + if (isset($this->error['cardconnect_api_password'])) { + $data['error_cardconnect_api_password'] = $this->error['cardconnect_api_password']; + } else { + $data['error_cardconnect_api_password'] = ''; + } + + if (isset($this->error['cardconnect_token'])) { + $data['error_cardconnect_token'] = $this->error['cardconnect_token']; + } else { + $data['error_cardconnect_token'] = ''; + } + + if (isset($this->error['cardconnect_site'])) { + $data['error_cardconnect_site'] = $this->error['cardconnect_site']; + } else { + $data['error_cardconnect_site'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cardconnect', $data)); + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/cardconnect'); + + $this->model_extension_payment_cardconnect->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/cardconnect'); + + $this->model_extension_payment_cardconnect->uninstall(); + } + } + + public function order() { + if ($this->config->get('cardconnect_status')) { + $this->load->model('extension/payment/cardconnect'); + + $order_id = $this->request->get['order_id']; + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->get['order_id']); + + if ($cardconnect_order) { + $this->load->language('extension/payment/cardconnect'); + + if ($cardconnect_order['payment_method'] == 'card') { + $cardconnect_order['payment_method'] = $this->language->get('text_card'); + } else { + $cardconnect_order['payment_method'] = $this->language->get('text_echeck'); + } + + $cardconnect_order['total_formatted'] = $this->currency->format($cardconnect_order['total'], $cardconnect_order['currency_code'], false, true); + + $cardconnect_order['total_captured'] = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $cardconnect_order['total_captured_formatted'] = $this->currency->format($cardconnect_order['total_captured'], $cardconnect_order['currency_code'], false, true); + + foreach($cardconnect_order['transactions'] as &$transaction) { + switch ($transaction['type']) { + case 'payment': + $transaction['type'] = 'Payment'; + break; + case 'auth': + $transaction['type'] = 'Authorize'; + break; + case 'refund': + $transaction['type'] = 'Refund'; + break; + case 'void': + $transaction['type'] = 'Void'; + break; + default: + $transaction['type'] = 'Payment'; + } + + $transaction['amount'] = $this->currency->format($transaction['amount'], $cardconnect_order['currency_code'], false, true); + + if ($transaction['status'] == 'Y') { + $transaction['status'] = 'Accepted'; + } else if ($transaction['status'] == 'N') { + $transaction['status'] = 'Rejected'; + } + + $transaction['date_modified'] = date($this->language->get('datetime_format'), strtotime($transaction['date_modified'])); + + $transaction['date_added'] = date($this->language->get('datetime_format'), strtotime($transaction['date_added'])); + } + + $data['cardconnect_order'] = $cardconnect_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/cardconnect_order', $data); + } + } + } + + public function inquire() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $inquire_response = $this->model_extension_payment_cardconnect->inquire($cardconnect_order, $this->request->post['retref']); + + if (isset($inquire_response['respstat']) && $inquire_response['respstat'] == 'C') { + $json['error'] = $inquire_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->updateTransactionStatusByRetref($this->request->post['retref'], $inquire_response['setlstat']); + + $json['status'] = $inquire_response['setlstat']; + + $json['date_modified'] = date($this->language->get('datetime_format')); + + $json['success'] = $this->language->get('text_inquire_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) { + if ($this->request->post['amount'] > 0) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $capture_response = $this->model_extension_payment_cardconnect->capture($cardconnect_order, $this->request->post['amount']); + + if (!isset($capture_response['retref'])) { + $json['error'] = $this->language->get('error_invalid_response'); + } else if (isset($capture_response['respstat']) && $capture_response['respstat'] == 'C') { + $json['error'] = $capture_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'payment', $capture_response['retref'], $this->request->post['amount'], $capture_response['setlstat']); + + $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $json['retref'] = $capture_response['retref']; + $json['amount'] = $this->currency->format($this->request->post['amount'], $cardconnect_order['currency_code'], false, true); + $json['status'] = $capture_response['setlstat']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true); + + $json['success'] = $this->language->get('text_capture_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_amount_zero'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) { + if ($this->request->post['amount'] > 0) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $refund_response = $this->model_extension_payment_cardconnect->refund($cardconnect_order, $this->request->post['amount']); + + if (!isset($refund_response['retref'])) { + $json['error'] = $this->language->get('error_invalid_response'); + } else if (isset($refund_response['respstat']) && $refund_response['respstat'] == 'C') { + $json['error'] = $refund_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'refund', $refund_response['retref'], $this->request->post['amount'] * -1, $refund_response['resptext']); + + $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $json['retref'] = $refund_response['retref']; + $json['amount'] = $this->currency->format($this->request->post['amount'] * -1, $cardconnect_order['currency_code'], false, true); + $json['status'] = $refund_response['resptext']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true); + + $json['success'] = $this->language->get('text_refund_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_amount_zero'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $void_response = $this->model_extension_payment_cardconnect->void($cardconnect_order, $this->request->post['retref']); + + if (!isset($void_response['authcode']) || $void_response['authcode'] != 'REVERS') { + $json['error'] = $void_response['resptext']; + } else { + $json['retref'] = $void_response['retref']; + $json['amount'] = $this->currency->format(0.00, $cardconnect_order['currency_code'], false, true); + $json['status'] = $void_response['resptext']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['success'] = $this->language->get('text_void_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cardconnect')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_cardconnect_merchant_id']) { + $this->error['payment_cardconnect_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['cardconnect_api_username']) { + $this->error['cardconnect_api_username'] = $this->language->get('error_api_username'); + } + + if (!$this->request->post['cardconnect_api_password']) { + $this->error['cardconnect_api_password'] = $this->language->get('error_api_password'); + } + + if (!$this->request->post['cardconnect_token']) { + $this->error['cardconnect_token'] = $this->language->get('error_token'); + } + + if (!$this->request->post['cardconnect_site']) { + $this->error['cardconnect_site'] = $this->language->get('error_site'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cardinity.php b/public/admin/controller/extension/payment/cardinity.php new file mode 100644 index 0000000..a6beda6 --- /dev/null +++ b/public/admin/controller/extension/payment/cardinity.php @@ -0,0 +1,304 @@ +<?php +class ControllerExtensionPaymentCardinity extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cardinity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cardinity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cardinity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cardinity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cardinity_key'])) { + $data['payment_cardinity_key'] = $this->request->post['payment_cardinity_key']; + } else { + $data['payment_cardinity_key'] = $this->config->get('payment_cardinity_key'); + } + + if (isset($this->request->post['payment_cardinity_secret'])) { + $data['payment_cardinity_secret'] = $this->request->post['payment_cardinity_secret']; + } else { + $data['payment_cardinity_secret'] = $this->config->get('payment_cardinity_secret'); + } + + if (isset($this->request->post['payment_cardinity_debug'])) { + $data['payment_cardinity_debug'] = $this->request->post['payment_cardinity_debug']; + } else { + $data['payment_cardinity_debug'] = $this->config->get('payment_cardinity_debug'); + } + + if (isset($this->request->post['payment_cardinity_total'])) { + $data['payment_cardinity_total'] = $this->request->post['payment_cardinity_total']; + } else { + $data['payment_cardinity_total'] = $this->config->get('payment_cardinity_total'); + } + + if (isset($this->request->post['payment_cardinity_order_status_id'])) { + $data['payment_cardinity_order_status_id'] = $this->request->post['payment_cardinity_order_status_id']; + } else { + $data['payment_cardinity_order_status_id'] = $this->config->get('payment_cardinity_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cardinity_geo_zone_id'])) { + $data['payment_cardinity_geo_zone_id'] = $this->request->post['payment_cardinity_geo_zone_id']; + } else { + $data['payment_cardinity_geo_zone_id'] = $this->config->get('payment_cardinity_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cardinity_status'])) { + $data['payment_cardinity_status'] = $this->request->post['payment_cardinity_status']; + } else { + $data['payment_cardinity_status'] = $this->config->get('payment_cardinity_status'); + } + + if (isset($this->request->post['payment_cardinity_sort_order'])) { + $data['payment_cardinity_sort_order'] = $this->request->post['payment_cardinity_sort_order']; + } else { + $data['payment_cardinity_sort_order'] = $this->config->get('payment_cardinity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cardinity', $data)); + } + + public function order() { + $this->load->language('extension/payment/cardinity'); + + $data['user_token'] = $this->session->data['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/cardinity_order', $data); + } + + public function getPayment() { + $this->load->language('extension/payment/cardinity'); + + $this->load->model('extension/payment/cardinity'); + + $data['column_refund'] = $this->language->get('column_refund'); + $data['column_date'] = $this->language->get('column_date'); + $data['column_refund_history'] = $this->language->get('column_refund_history'); + $data['column_action'] = $this->language->get('column_action'); + $data['column_status'] = $this->language->get('column_status'); + $data['column_amount'] = $this->language->get('column_amount'); + $data['column_description'] = $this->language->get('column_description'); + + $data['button_refund'] = $this->language->get('button_refund'); + + $data['user_token'] = $this->session->data['user_token']; + + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->config->get('payment_cardinity_key'), + 'secret' => $this->config->get('payment_cardinity_secret') + )); + + $order = $this->model_extension_payment_cardinity->getOrder($this->request->get['order_id']); + + $data['payment'] = false; + + $data['refunds'] = array(); + + if ($order && $order['payment_id']) { + $data['payment'] = true; + + $payment = $this->model_extension_payment_cardinity->getPayment($client, $order['payment_id']); + + $data['refund_action'] = false; + + $successful_statuses = array( + 'approved' + ); + + if (in_array($payment->getStatus(), $successful_statuses)) { + $data['refund_action'] = true; + } + + $max_refund_amount = $payment->getAmount(); + + $refunds = $this->model_extension_payment_cardinity->getRefunds($client, $order['payment_id']); + + if ($refunds) { + foreach ($refunds as $refund) { + $successful_refund_statuses = array( + 'approved' + ); + + if (in_array($refund->getStatus(), $successful_refund_statuses)) { + $max_refund_amount -= $refund->getAmount(); + } + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($refund->getCreated())), + 'amount' => $this->currency->format($refund->getAmount(), $refund->getCurrency(), '1.00000000', true), + 'status' => $refund->getStatus(), + 'description' => $refund->getDescription() + ); + } + } + + if (!$max_refund_amount) { + $data['refund_action'] = false; + } + + $data['payment_id'] = $payment->getId(); + $data['symbol_left'] = $this->currency->getSymbolLeft($payment->getCurrency()); + $data['symbol_right'] = $this->currency->getSymbolRight($payment->getCurrency()); + + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $payment->getCurrency(), '1.00000000', false); + } + + $this->response->setOutput($this->load->view('extension/payment/cardinity_order_ajax', $data)); + } + + public function refund() { + $this->load->language('extension/payment/cardinity'); + + $this->load->model('extension/payment/cardinity'); + + $json = array(); + + $success = $error = ''; + + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->config->get('payment_cardinity_key'), + 'secret' => $this->config->get('payment_cardinity_secret') + )); + + $refund = $this->model_extension_payment_cardinity->refundPayment($client, $this->request->post['payment_id'], (float)number_format($this->request->post['amount'], 2), $this->request->post['description']); + + if ($refund) { + $success = $this->language->get('text_success_action'); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + $this->load->model('extension/payment/cardinity'); + + $check_credentials = true; + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/cardinity')) { + $this->error['warning'] = $this->language->get('error_permission'); + + $check_credentials = false; + } + + if (!$this->request->post['payment_cardinity_key']) { + $this->error['key'] = $this->language->get('error_key'); + + $check_credentials = false; + } + + if (!$this->request->post['payment_cardinity_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + + $check_credentials = false; + } + + if (!class_exists('Cardinity\Client')) { + $this->error['warning'] = $this->language->get('error_composer'); + + $check_credentials = false; + } + + if ($check_credentials) { + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->request->post['payment_cardinity_key'], + 'secret' => $this->request->post['payment_cardinity_secret'] + )); + + $verify_credentials = $this->model_extension_payment_cardinity->verifyCredentials($client); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/payment/cardinity'); + + $this->model_extension_payment_cardinity->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/cardinity'); + + $this->model_extension_payment_cardinity->uninstall(); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cheque.php b/public/admin/controller/extension/payment/cheque.php new file mode 100644 index 0000000..0b77697 --- /dev/null +++ b/public/admin/controller/extension/payment/cheque.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionPaymentCheque extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cheque'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cheque', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['payable'])) { + $data['error_payable'] = $this->error['payable']; + } else { + $data['error_payable'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cheque', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cheque', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cheque_payable'])) { + $data['payment_cheque_payable'] = $this->request->post['payment_cheque_payable']; + } else { + $data['payment_cheque_payable'] = $this->config->get('payment_cheque_payable'); + } + + if (isset($this->request->post['payment_cheque_total'])) { + $data['payment_cheque_total'] = $this->request->post['payment_cheque_total']; + } else { + $data['payment_cheque_total'] = $this->config->get('payment_cheque_total'); + } + + if (isset($this->request->post['payment_cheque_order_status_id'])) { + $data['payment_cheque_order_status_id'] = $this->request->post['payment_cheque_order_status_id']; + } else { + $data['payment_cheque_order_status_id'] = $this->config->get('payment_cheque_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cheque_geo_zone_id'])) { + $data['payment_cheque_geo_zone_id'] = $this->request->post['payment_cheque_geo_zone_id']; + } else { + $data['payment_cheque_geo_zone_id'] = $this->config->get('payment_cheque_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cheque_status'])) { + $data['payment_cheque_status'] = $this->request->post['payment_cheque_status']; + } else { + $data['payment_cheque_status'] = $this->config->get('payment_cheque_status'); + } + + if (isset($this->request->post['payment_cheque_sort_order'])) { + $data['payment_cheque_sort_order'] = $this->request->post['payment_cheque_sort_order']; + } else { + $data['payment_cheque_sort_order'] = $this->config->get('payment_cheque_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cheque', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cheque')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_cheque_payable']) { + $this->error['payable'] = $this->language->get('error_payable'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cod.php b/public/admin/controller/extension/payment/cod.php new file mode 100644 index 0000000..46c351d --- /dev/null +++ b/public/admin/controller/extension/payment/cod.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionPaymentCod extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cod'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cod', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cod', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cod', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cod_total'])) { + $data['payment_cod_total'] = $this->request->post['payment_cod_total']; + } else { + $data['payment_cod_total'] = $this->config->get('payment_cod_total'); + } + + if (isset($this->request->post['payment_cod_order_status_id'])) { + $data['payment_cod_order_status_id'] = $this->request->post['payment_cod_order_status_id']; + } else { + $data['payment_cod_order_status_id'] = $this->config->get('payment_cod_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cod_geo_zone_id'])) { + $data['payment_cod_geo_zone_id'] = $this->request->post['payment_cod_geo_zone_id']; + } else { + $data['payment_cod_geo_zone_id'] = $this->config->get('payment_cod_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cod_status'])) { + $data['payment_cod_status'] = $this->request->post['payment_cod_status']; + } else { + $data['payment_cod_status'] = $this->config->get('payment_cod_status'); + } + + if (isset($this->request->post['payment_cod_sort_order'])) { + $data['payment_cod_sort_order'] = $this->request->post['payment_cod_sort_order']; + } else { + $data['payment_cod_sort_order'] = $this->config->get('payment_cod_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cod', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cod')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/divido.php b/public/admin/controller/extension/payment/divido.php new file mode 100644 index 0000000..d358764 --- /dev/null +++ b/public/admin/controller/extension/payment/divido.php @@ -0,0 +1,215 @@ +<?php +class ControllerExtensionPaymentDivido extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/divido'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + $this->load->model('extension/payment/divido'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { + $this->model_setting_setting->editSetting('payment_divido', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['entry_plans_options'] = array( + 'all' => $this->language->get('entry_plans_options_all'), + 'selected' => $this->language->get('entry_plans_options_selected'), + ); + + $data['entry_products_options']= array( + 'all' => $this->language->get('entry_products_options_all'), + 'selected' => $this->language->get('entry_products_options_selected'), + 'threshold' => $this->language->get('entry_products_options_threshold'), + ); + + $data['button_save'] = $this->language->get('button_save'); + $data['button_cancel'] = $this->language->get('button_cancel'); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], 'SSL'); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', 'SSL'); + + if (isset($this->request->post['payment_divido_api_key'])) { + $data['payment_divido_api_key'] = $this->request->post['payment_divido_api_key']; + } else { + $data['payment_divido_api_key'] = $this->config->get('payment_divido_api_key'); + } + + if (isset($this->request->post['payment_divido_order_status_id'])) { + $data['payment_divido_order_status_id'] = $this->request->post['payment_divido_order_status_id']; + } elseif ($this->config->get('payment_divido_order_status_id')) { + $data['payment_divido_order_status_id'] = $this->config->get('payment_divido_order_status_id'); + } else { + $data['payment_divido_order_status_id'] = 2; + } + + if (isset($this->request->post['payment_divido_status'])) { + $data['payment_divido_status'] = $this->request->post['payment_divido_status']; + } else { + $data['payment_divido_status'] = $this->config->get('payment_divido_status'); + } + + if (isset($this->request->post['payment_divido_sort_order'])) { + $data['payment_divido_sort_order'] = $this->request->post['payment_divido_sort_order']; + } else { + $data['payment_divido_sort_order'] = $this->config->get('payment_divido_sort_order'); + } + + if (isset($this->request->post['payment_divido_title'])) { + $data['payment_divido_title'] = $this->request->post['payment_divido_title']; + } else { + $data['payment_divido_title'] = $this->config->get('payment_divido_title'); + } + + if (isset($this->request->post['payment_divido_productselection'])) { + $data['payment_divido_productselection'] = $this->request->post['payment_divido_productselection']; + } else { + $data['payment_divido_productselection'] = $this->config->get('payment_divido_productselection'); + } + + if (isset($this->request->post['payment_divido_price_threshold'])) { + $data['payment_divido_price_threshold'] = $this->request->post['payment_divido_price_threshold']; + } else { + $data['payment_divido_price_threshold'] = $this->config->get('payment_divido_price_threshold'); + } + + if (isset($this->request->post['payment_divido_cart_threshold'])) { + $data['payment_divido_cart_threshold'] = $this->request->post['payment_divido_cart_threshold']; + } else { + $data['payment_divido_cart_threshold'] = $this->config->get('payment_divido_cart_threshold'); + } + + if (isset($this->request->post['payment_divido_planselection'])) { + $data['payment_divido_planselection'] = $this->request->post['payment_divido_planselection']; + } else { + $data['payment_divido_planselection'] = $this->config->get('payment_divido_planselection'); + } + + if (isset($this->request->post['payment_divido_plans_selected'])) { + $data['payment_divido_plans_selected'] = $this->request->post['payment_divido_plans_selected']; + } elseif ($this->config->get('payment_divido_plans_selected')) { + $data['payment_divido_plans_selected'] = $this->config->get('payment_divido_plans_selected'); + } else { + $data['payment_divido_plans_selected'] = array(); + } + + if (isset($this->request->post['payment_divido_categories'])) { + $data['payment_divido_categories'] = $this->request->post['payment_divido_categories']; + } elseif ($this->config->get('payment_divido_categories')) { + $data['payment_divido_categories'] = $this->config->get('payment_divido_categories'); + } else { + $data['payment_divido_categories'] = array(); + } + + $data['categories'] = array(); + + $this->load->model('catalog/category'); + + foreach ($data['payment_divido_categories'] as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $data['categories'][] = array( + 'category_id' => $category_info['category_id'], + 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] + ); + } + } + + try { + $data['divido_plans'] = $this->model_extension_payment_divido->getAllPlans(); + } catch (Exception $e) { + $this->log->write($e->getMessage()); + $data['divido_plans'] = array(); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/divido', $data)); + } + + + public function order() { + if (!$this->config->get('payment_divido_status')) { + return null; + } + + $this->load->model('extension/payment/divido'); + $this->load->language('extension/payment/divido'); + + $order_id = $this->request->get['order_id']; + + $lookup = $this->model_extension_payment_divido->getLookupByOrderId($order_id); + $proposal_id = null; + $application_id = null; + $deposit_amount = null; + if ($lookup->num_rows == 1) { + $lookup_data = $lookup->row; + $proposal_id = $lookup_data['proposal_id']; + $application_id = $lookup_data['application_id']; + $deposit_amount = $lookup_data['deposit_amount']; + } + + $data['proposal_id'] = $proposal_id; + $data['application_id'] = $application_id; + $data['deposit_amount'] = $deposit_amount; + + return $this->load->view('extension/payment/divido_order', $data); + } + + public function install() { + $this->load->model('extension/payment/divido'); + $this->model_extension_payment_divido->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/divido'); + $this->model_extension_payment_divido->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/divido')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/eway.php b/public/admin/controller/extension/payment/eway.php new file mode 100644 index 0000000..26f8c43 --- /dev/null +++ b/public/admin/controller/extension/payment/eway.php @@ -0,0 +1,371 @@ +<?php +class ControllerExtensionPaymentEway extends Controller { + + private $error = array(); + + public function index() { + $this->load->language('extension/payment/eway'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('payment_eway', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['payment_type'])) { + $data['error_payment_type'] = $this->error['payment_type']; + } else { + $data['error_payment_type'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['payment_eway_payment_gateway'])) { + $data['payment_eway_payment_gateway'] = $this->request->post['payment_eway_payment_gateway']; + } else { + $data['payment_eway_payment_gateway'] = $this->config->get('payment_eway_payment_gateway'); + } + + if (isset($this->request->post['payment_eway_paymode'])) { + $data['payment_eway_paymode'] = $this->request->post['payment_eway_paymode']; + } else { + $data['payment_eway_paymode'] = $this->config->get('payment_eway_paymode'); + } + + if (isset($this->request->post['payment_eway_test'])) { + $data['payment_eway_test'] = $this->request->post['payment_eway_test']; + } else { + $data['payment_eway_test'] = $this->config->get('payment_eway_test'); + } + + if (isset($this->request->post['payment_eway_payment_type'])) { + $data['payment_eway_payment_type'] = $this->request->post['payment_eway_payment_type']; + } else { + $data['payment_eway_payment_type'] = $this->config->get('payment_eway_payment_type'); + } + + if (isset($this->request->post['payment_eway_transaction'])) { + $data['payment_eway_transaction'] = $this->request->post['payment_eway_transaction']; + } else { + $data['payment_eway_transaction'] = $this->config->get('payment_eway_transaction'); + } + + if (isset($this->request->post['payment_eway_standard_geo_zone_id'])) { + $data['payment_eway_standard_geo_zone_id'] = $this->request->post['payment_eway_standard_geo_zone_id']; + } else { + $data['payment_eway_standard_geo_zone_id'] = $this->config->get('payment_eway_standard_geo_zone_id'); + } + + if (isset($this->request->post['payment_eway_order_status_id'])) { + $data['payment_eway_order_status_id'] = $this->request->post['payment_eway_order_status_id']; + } else { + $data['payment_eway_order_status_id'] = $this->config->get('payment_eway_order_status_id'); + } + + if (isset($this->request->post['payment_eway_order_status_refunded_id'])) { + $data['payment_eway_order_status_refunded_id'] = $this->request->post['payment_eway_order_status_refunded_id']; + } else { + $data['payment_eway_order_status_refunded_id'] = $this->config->get('payment_eway_order_status_refunded_id'); + } + + if (isset($this->request->post['payment_eway_order_status_auth_id'])) { + $data['payment_eway_order_status_auth_id'] = $this->request->post['payment_eway_order_status_auth_id']; + } else { + $data['payment_eway_order_status_auth_id'] = $this->config->get('payment_eway_order_status_auth_id'); + } + + if (isset($this->request->post['payment_eway_order_status_fraud_id'])) { + $data['payment_eway_order_status_fraud_id'] = $this->request->post['payment_eway_order_status_fraud_id']; + } else { + $data['payment_eway_order_status_fraud_id'] = $this->config->get('payment_eway_order_status_fraud_id'); + } + + if (isset($this->request->post['payment_eway_transaction_method'])) { + $data['payment_eway_transaction_method'] = $this->request->post['payment_eway_transaction_method']; + } else { + $data['payment_eway_transaction_method'] = $this->config->get('payment_eway_transaction_method'); + } + + if (isset($this->request->post['payment_eway_username'])) { + $data['payment_eway_username'] = $this->request->post['payment_eway_username']; + } else { + $data['payment_eway_username'] = $this->config->get('payment_eway_username'); + } + + if (isset($this->request->post['payment_eway_password'])) { + $data['payment_eway_password'] = $this->request->post['payment_eway_password']; + } else { + $data['payment_eway_password'] = $this->config->get('payment_eway_password'); + } + + if (isset($this->request->post['payment_eway_status'])) { + $data['payment_eway_status'] = $this->request->post['payment_eway_status']; + } else { + $data['payment_eway_status'] = $this->config->get('payment_eway_status'); + } + + if (isset($this->request->post['payment_eway_sort_order'])) { + $data['payment_eway_sort_order'] = $this->request->post['payment_eway_sort_order']; + } else { + $data['payment_eway_sort_order'] = $this->config->get('payment_eway_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/eway', $data)); + } + + public function install() { + $this->load->model('extension/payment/eway'); + $this->model_extension_payment_eway->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/eway'); + $this->model_extension_payment_eway->uninstall(); + } + + // Legacy 2.0.0 + public function orderAction() { + return $this->order(); + } + + // Legacy 2.0.3 + public function action() { + return $this->order(); + } + + public function order() { + if ($this->config->get('payment_eway_status')) { + $this->load->model('extension/payment/eway'); + + $eway_order = $this->model_extension_payment_eway->getOrder($this->request->get['order_id']); + + if (!empty($eway_order)) { + $this->load->language('extension/payment/eway'); + + $eway_order['total'] = $eway_order['amount']; + $eway_order['total_formatted'] = $this->currency->format($eway_order['amount'], $eway_order['currency_code'], 1, true); + + $eway_order['total_captured'] = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $eway_order['total_captured_formatted'] = $this->currency->format($eway_order['total_captured'], $eway_order['currency_code'], 1, true); + + $eway_order['uncaptured'] = $eway_order['total'] - $eway_order['total_captured']; + + $eway_order['total_refunded'] = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + $eway_order['total_refunded_formatted'] = $this->currency->format($eway_order['total_refunded'], $eway_order['currency_code'], 1, true); + + $eway_order['unrefunded'] = $eway_order['total_captured'] - $eway_order['total_refunded']; + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_created'] = $this->language->get('text_column_created'); + $data['text_column_transactionid'] = $this->language->get('text_column_transactionid'); + $data['btn_refund'] = $this->language->get('btn_refund'); + $data['btn_capture'] = $this->language->get('btn_capture'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_total_refunded'] = $this->language->get('text_total_refunded'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_refund_status'] = $this->language->get('text_refund_status'); + + $data['text_empty_refund'] = $this->language->get('text_empty_refund'); + $data['text_empty_capture'] = $this->language->get('text_empty_capture'); + + $data['eway_order'] = $eway_order; + $data['user_token'] = $this->request->get['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/eway_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/eway'); + + $order_id = $this->request->post['order_id']; + $refund_amount = (double)$this->request->post['refund_amount']; + + if ($order_id && $refund_amount > 0) { + $this->load->model('extension/payment/eway'); + $result = $this->model_extension_payment_eway->refund($order_id, $refund_amount); + + // Check if any error returns + if (isset($result->Errors) || $result === false) { + $json['error'] = true; + $reason = ''; + if ($result === false) { + $reason = $this->language->get('text_unknown_failure'); + } else { + $errors = explode(',', $result->Errors); + foreach ($errors as $error) { + $reason .= $this->language->get('text_card_message_' . $result->Errors); + } + } + $json['message'] = $this->language->get('text_refund_failed') . $reason; + } else { + $eway_order = $this->model_extension_payment_eway->getOrder($order_id); + $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->Refund->TransactionID, 'refund', $result->Refund->TotalAmount / 100, $eway_order['currency_code']); + + $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + $refund_status = 0; + + if ($total_captured == $total_refunded) { + $refund_status = 1; + $this->model_extension_payment_eway->updateRefundStatus($eway_order['eway_order_id'], $refund_status); + } + + $json['data'] = array(); + $json['data']['transactionid'] = $result->TransactionID; + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = number_format($refund_amount, 2, '.', ''); + $json['data']['total_refunded_formatted'] = $this->currency->format($total_refunded, $eway_order['currency_code'], 1, true); + $json['data']['refund_status'] = $refund_status; + $json['data']['remaining'] = $total_captured - $total_refunded; + $json['message'] = $this->language->get('text_refund_success'); + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['message'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/eway'); + + $order_id = $this->request->post['order_id']; + $capture_amount = (double)$this->request->post['capture_amount']; + + if ($order_id && $capture_amount > 0) { + $this->load->model('extension/payment/eway'); + $eway_order = $this->model_extension_payment_eway->getOrder($order_id); + $result = $this->model_extension_payment_eway->capture($order_id, $capture_amount, $eway_order['currency_code']); + + // Check if any error returns + if (isset($result->Errors) || $result === false) { + $json['error'] = true; + $reason = ''; + if ($result === false) { + $reason = $this->language->get('text_unknown_failure'); + } else { + $errors = explode(',', $result->Errors); + foreach ($errors as $error) { + $reason .= $this->language->get('text_card_message_' . $result->Errors); + } + } + $json['message'] = $this->language->get('text_capture_failed') . $reason; + } else { + $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->TransactionID, 'payment', $capture_amount, $eway_order['currency_code']); + + $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + + $remaining = $eway_order['amount'] - $capture_amount; + if ($remaining <= 0) { + $remaining = 0; + } + + $this->model_extension_payment_eway->updateCaptureStatus($eway_order['eway_order_id'], 1); + $this->model_extension_payment_eway->updateTransactionId($eway_order['eway_order_id'], $result->TransactionID); + + $json['data'] = array(); + $json['data']['transactionid'] = $result->TransactionID; + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = number_format($capture_amount, 2, '.', ''); + $json['data']['total_captured_formatted'] = $this->currency->format($total_captured, $eway_order['currency_code'], 1, true); + $json['data']['capture_status'] = 1; + $json['data']['remaining'] = $remaining; + $json['message'] = $this->language->get('text_capture_success'); + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['message'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/eway')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + if (!$this->request->post['payment_eway_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + if (!$this->request->post['payment_eway_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + if (!isset($this->request->post['payment_eway_payment_type'])) { + $this->error['payment_type'] = $this->language->get('error_payment_type'); + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/firstdata.php b/public/admin/controller/extension/payment/firstdata.php new file mode 100644 index 0000000..66f33f7 --- /dev/null +++ b/public/admin/controller/extension/payment/firstdata.php @@ -0,0 +1,352 @@ +<?php +class ControllerExtensionPaymentFirstdata extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/firstdata'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_firstdata', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify'; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_firstdata_merchant_id'])) { + $data['payment_firstdata_merchant_id'] = $this->request->post['payment_firstdata_merchant_id']; + } else { + $data['payment_firstdata_merchant_id'] = $this->config->get('payment_firstdata_merchant_id'); + } + + if (isset($this->request->post['payment_firstdata_secret'])) { + $data['payment_firstdata_secret'] = $this->request->post['payment_firstdata_secret']; + } else { + $data['payment_firstdata_secret'] = $this->config->get('payment_firstdata_secret'); + } + + if (isset($this->request->post['payment_firstdata_live_demo'])) { + $data['payment_firstdata_live_demo'] = $this->request->post['payment_firstdata_live_demo']; + } else { + $data['payment_firstdata_live_demo'] = $this->config->get('payment_firstdata_live_demo'); + } + + if (isset($this->request->post['payment_firstdata_geo_zone_id'])) { + $data['payment_firstdata_geo_zone_id'] = $this->request->post['payment_firstdata_geo_zone_id']; + } else { + $data['payment_firstdata_geo_zone_id'] = $this->config->get('payment_firstdata_geo_zone_id'); + } + + if (isset($this->request->post['payment_firstdata_total'])) { + $data['payment_firstdata_total'] = $this->request->post['payment_firstdata_total']; + } else { + $data['payment_firstdata_total'] = $this->config->get('payment_firstdata_total'); + } + + if (isset($this->request->post['payment_firstdata_sort_order'])) { + $data['payment_firstdata_sort_order'] = $this->request->post['payment_firstdata_sort_order']; + } else { + $data['payment_firstdata_sort_order'] = $this->config->get('payment_firstdata_sort_order'); + } + + if (isset($this->request->post['payment_firstdata_status'])) { + $data['payment_firstdata_status'] = $this->request->post['payment_firstdata_status']; + } else { + $data['payment_firstdata_status'] = $this->config->get('payment_firstdata_status'); + } + + if (isset($this->request->post['payment_firstdata_debug'])) { + $data['payment_firstdata_debug'] = $this->request->post['payment_firstdata_debug']; + } else { + $data['payment_firstdata_debug'] = $this->config->get('payment_firstdata_debug'); + } + + if (isset($this->request->post['payment_firstdata_auto_settle'])) { + $data['payment_firstdata_auto_settle'] = $this->request->post['payment_firstdata_auto_settle']; + } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('payment_firstdata_auto_settle') != '') { + $data['payment_firstdata_auto_settle'] = $this->config->get('payment_firstdata_auto_settle'); + } else { + $data['payment_firstdata_auto_settle'] = 1; + } + + if (isset($this->request->post['payment_firstdata_order_status_success_settled_id'])) { + $data['payment_firstdata_order_status_success_settled_id'] = $this->request->post['payment_firstdata_order_status_success_settled_id']; + } else { + $data['payment_firstdata_order_status_success_settled_id'] = $this->config->get('payment_firstdata_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_success_unsettled_id'])) { + $data['payment_firstdata_order_status_success_unsettled_id'] = $this->request->post['payment_firstdata_order_status_success_unsettled_id']; + } else { + $data['payment_firstdata_order_status_success_unsettled_id'] = $this->config->get('payment_firstdata_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_decline_id'])) { + $data['payment_firstdata_order_status_decline_id'] = $this->request->post['payment_firstdata_order_status_decline_id']; + } else { + $data['payment_firstdata_order_status_decline_id'] = $this->config->get('payment_firstdata_order_status_decline_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_void_id'])) { + $data['payment_firstdata_order_status_void_id'] = $this->request->post['payment_firstdata_order_status_void_id']; + } else { + $data['payment_firstdata_order_status_void_id'] = $this->config->get('payment_firstdata_order_status_void_id'); + } + + if (isset($this->request->post['payment_firstdata_live_url'])) { + $data['payment_firstdata_live_url'] = $this->request->post['payment_firstdata_live_url']; + } else { + $data['payment_firstdata_live_url'] = $this->config->get('payment_firstdata_live_url'); + } + + if (empty($data['payment_firstdata_live_url'])) { + $data['payment_firstdata_live_url'] = 'https://ipg-online.com/connect/gateway/processing'; + } + + if (isset($this->request->post['payment_firstdata_demo_url'])) { + $data['payment_firstdata_demo_url'] = $this->request->post['payment_firstdata_demo_url']; + } else { + $data['payment_firstdata_demo_url'] = $this->config->get('payment_firstdata_demo_url'); + } + + if (isset($this->request->post['payment_firstdata_card_storage'])) { + $data['payment_firstdata_card_storage'] = $this->request->post['payment_firstdata_card_storage']; + } else { + $data['payment_firstdata_card_storage'] = $this->config->get('payment_firstdata_card_storage'); + } + + if (empty($data['payment_firstdata_demo_url'])) { + $data['payment_firstdata_demo_url'] = 'https://test.ipg-online.com/connect/gateway/processing'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/firstdata', $data)); + } + + public function install() { + $this->load->model('extension/payment/firstdata'); + $this->model_extension_payment_firstdata->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/firstdata'); + $this->model_extension_payment_firstdata->uninstall(); + } + + public function order() { + if ($this->config->get('payment_firstdata_status')) { + $this->load->model('extension/payment/firstdata'); + + $firstdata_order = $this->model_extension_payment_firstdata->getOrder($this->request->get['order_id']); + + if (!empty($firstdata_order)) { + $this->load->language('extension/payment/firstdata'); + + $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata->getTotalCaptured($firstdata_order['firstdata_order_id']); + $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true); + $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true); + + $data['firstdata_order'] = $firstdata_order; + $data['merchant_id'] = $this->config->get('payment_firstdata_merchant_id'); + $data['currency'] = $this->model_extension_payment_firstdata->mapCurrency($firstdata_order['currency_code']); + $data['amount'] = number_format($firstdata_order['total'], 2); + + $data['request_timestamp'] = date("Y:m:d-H:i:s"); + + $data['hash'] = sha1(bin2hex($data['merchant_id'] . $data['request_timestamp'] . $data['amount'] . $data['currency'] . $this->config->get('payment_firstdata_secret'))); + + $data['void_url'] = $this->url->link('extension/payment/firstdata/void', 'user_token=' . $this->session->data['user_token'], true); + $data['capture_url'] = $this->url->link('extension/payment/firstdata/capture', 'user_token=' . $this->session->data['user_token'], true); + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify'; + + if ($this->config->get('payment_firstdata_live_demo') == 1) { + $data['action_url'] = $this->config->get('payment_firstdata_live_url'); + } else { + $data['action_url'] = $this->config->get('payment_firstdata_demo_url'); + } + + if (isset($this->session->data['void_success'])) { + $data['void_success'] = $this->session->data['void_success']; + + unset($this->session->data['void_success']); + } else { + $data['void_success'] = ''; + } + + if (isset($this->session->data['void_error'])) { + $data['void_error'] = $this->session->data['void_error']; + + unset($this->session->data['void_error']); + } else { + $data['void_error'] = ''; + } + + if (isset($this->session->data['capture_success'])) { + $data['capture_success'] = $this->session->data['capture_success']; + + unset($this->session->data['capture_success']); + } else { + $data['capture_success'] = ''; + } + + if (isset($this->session->data['capture_error'])) { + $data['capture_error'] = $this->session->data['capture_error']; + + unset($this->session->data['capture_error']); + } else { + $data['capture_error'] = ''; + } + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_ref'] = $this->language->get('text_order_ref'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_yes'] = $this->language->get('text_yes'); + $data['text_no'] = $this->language->get('text_no'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_date_added'] = $this->language->get('text_column_date_added'); + $data['button_capture'] = $this->language->get('button_capture'); + $data['button_void'] = $this->language->get('button_void'); + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/firstdata_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/firstdata'); + + if ($this->request->post['status'] == 'FAILED') { + if (isset($this->request->post['fail_reason'])) { + $this->session->data['void_error'] = $this->request->post['fail_reason']; + } else { + $this->session->data['void_error'] = $this->language->get('error_void_error'); + } + } + + if ($this->request->post['status'] == 'DECLINED') { + $this->session->data['void_success'] = $this->language->get('success_void'); + } + + $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function capture() { + $this->load->language('extension/payment/firstdata'); + + if ($this->request->post['status'] == 'FAILED') { + if (isset($this->request->post['fail_reason'])) { + $this->session->data['capture_error'] = $this->request->post['fail_reason']; + } else { + $this->session->data['capture_error'] = $this->language->get('error_capture_error'); + } + } + + if ($this->request->post['status'] == 'APPROVED') { + $this->session->data['capture_success'] = $this->language->get('success_capture'); + } + + $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/firstdata')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_firstdata_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_firstdata_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_firstdata_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_firstdata_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/firstdata_remote.php b/public/admin/controller/extension/payment/firstdata_remote.php new file mode 100644 index 0000000..1380a1b --- /dev/null +++ b/public/admin/controller/extension/payment/firstdata_remote.php @@ -0,0 +1,482 @@ +<?php +class ControllerExtensionPaymentFirstdataRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/firstdata_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_firstdata_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_user_id'])) { + $data['error_user_id'] = $this->error['error_user_id']; + } else { + $data['error_user_id'] = ''; + } + + if (isset($this->error['error_password'])) { + $data['error_password'] = $this->error['error_password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['error_certificate'])) { + $data['error_certificate'] = $this->error['error_certificate']; + } else { + $data['error_certificate'] = ''; + } + + if (isset($this->error['error_key'])) { + $data['error_key'] = $this->error['error_key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['error_key_pw'])) { + $data['error_key_pw'] = $this->error['error_key_pw']; + } else { + $data['error_key_pw'] = ''; + } + + if (isset($this->error['error_ca'])) { + $data['error_ca'] = $this->error['error_ca']; + } else { + $data['error_ca'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['action'] = $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['firstdata_remote_merchant_id'])) { + $data['firstdata_remote_merchant_id'] = $this->request->post['firstdata_remote_merchant_id']; + } else { + $data['firstdata_remote_merchant_id'] = $this->config->get('firstdata_remote_merchant_id'); + } + + if (isset($this->request->post['firstdata_remote_user_id'])) { + $data['firstdata_remote_user_id'] = $this->request->post['firstdata_remote_user_id']; + } else { + $data['firstdata_remote_user_id'] = $this->config->get('firstdata_remote_user_id'); + } + + if (isset($this->request->post['firstdata_remote_password'])) { + $data['firstdata_remote_password'] = $this->request->post['firstdata_remote_password']; + } else { + $data['firstdata_remote_password'] = $this->config->get('firstdata_remote_password'); + } + + if (isset($this->request->post['firstdata_remote_certificate'])) { + $data['firstdata_remote_certificate'] = $this->request->post['firstdata_remote_certificate']; + } else { + $data['firstdata_remote_certificate'] = $this->config->get('firstdata_remote_certificate'); + } + + if (isset($this->request->post['firstdata_remote_key'])) { + $data['firstdata_remote_key'] = $this->request->post['firstdata_remote_key']; + } else { + $data['firstdata_remote_key'] = $this->config->get('firstdata_remote_key'); + } + + if (isset($this->request->post['firstdata_remote_key_pw'])) { + $data['firstdata_remote_key_pw'] = $this->request->post['firstdata_remote_key_pw']; + } else { + $data['firstdata_remote_key_pw'] = $this->config->get('firstdata_remote_key_pw'); + } + + if (isset($this->request->post['firstdata_remote_ca'])) { + $data['firstdata_remote_ca'] = $this->request->post['firstdata_remote_ca']; + } else { + $data['firstdata_remote_ca'] = $this->config->get('firstdata_remote_ca'); + } + + if (isset($this->request->post['firstdata_remote_geo_zone_id'])) { + $data['firstdata_remote_geo_zone_id'] = $this->request->post['firstdata_remote_geo_zone_id']; + } else { + $data['firstdata_remote_geo_zone_id'] = $this->config->get('firstdata_remote_geo_zone_id'); + } + + if (isset($this->request->post['firstdata_remote_total'])) { + $data['firstdata_remote_total'] = $this->request->post['firstdata_remote_total']; + } else { + $data['firstdata_remote_total'] = $this->config->get('firstdata_remote_total'); + } + + if (isset($this->request->post['firstdata_remote_sort_order'])) { + $data['firstdata_remote_sort_order'] = $this->request->post['firstdata_remote_sort_order']; + } else { + $data['firstdata_remote_sort_order'] = $this->config->get('firstdata_remote_sort_order'); + } + + if (isset($this->request->post['firstdata_remote_status'])) { + $data['firstdata_remote_status'] = $this->request->post['firstdata_remote_status']; + } else { + $data['firstdata_remote_status'] = $this->config->get('firstdata_remote_status'); + } + + if (isset($this->request->post['firstdata_remote_debug'])) { + $data['firstdata_remote_debug'] = $this->request->post['firstdata_remote_debug']; + } else { + $data['firstdata_remote_debug'] = $this->config->get('firstdata_remote_debug'); + } + if (isset($this->request->post['firstdata_remote_auto_settle'])) { + $data['firstdata_remote_auto_settle'] = $this->request->post['firstdata_remote_auto_settle']; + } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('firstdata_remote_auto_settle') != '') { + $data['firstdata_remote_auto_settle'] = $this->config->get('firstdata_remote_auto_settle'); + } else { + $data['firstdata_remote_auto_settle'] = 1; + } + + if (isset($this->request->post['firstdata_remote_3d'])) { + $data['firstdata_remote_3d'] = $this->request->post['firstdata_remote_3d']; + } else { + $data['firstdata_remote_3d'] = $this->config->get('firstdata_remote_3d'); + } + + if (isset($this->request->post['firstdata_remote_liability'])) { + $data['firstdata_remote_liability'] = $this->request->post['firstdata_remote_liability']; + } else { + $data['firstdata_remote_liability'] = $this->config->get('firstdata_remote_liability'); + } + + if (isset($this->request->post['firstdata_remote_order_status_success_settled_id'])) { + $data['firstdata_remote_order_status_success_settled_id'] = $this->request->post['firstdata_remote_order_status_success_settled_id']; + } else { + $data['firstdata_remote_order_status_success_settled_id'] = $this->config->get('firstdata_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_success_unsettled_id'])) { + $data['firstdata_remote_order_status_success_unsettled_id'] = $this->request->post['firstdata_remote_order_status_success_unsettled_id']; + } else { + $data['firstdata_remote_order_status_success_unsettled_id'] = $this->config->get('firstdata_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_decline_id'])) { + $data['firstdata_remote_order_status_decline_id'] = $this->request->post['firstdata_remote_order_status_decline_id']; + } else { + $data['firstdata_remote_order_status_decline_id'] = $this->config->get('firstdata_remote_order_status_decline_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_void_id'])) { + $data['firstdata_remote_order_status_void_id'] = $this->request->post['firstdata_remote_order_status_void_id']; + } else { + $data['firstdata_remote_order_status_void_id'] = $this->config->get('firstdata_remote_order_status_void_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_refunded_id'])) { + $data['firstdata_remote_order_status_refunded_id'] = $this->request->post['firstdata_remote_order_status_refunded_id']; + } else { + $data['firstdata_remote_order_status_refunded_id'] = $this->config->get('firstdata_remote_order_status_refunded_id'); + } + + if (isset($this->request->post['firstdata_remote_card_storage'])) { + $data['firstdata_remote_card_storage'] = $this->request->post['firstdata_remote_card_storage']; + } else { + $data['firstdata_remote_card_storage'] = $this->config->get('firstdata_remote_card_storage'); + } + + $data['cards'] = array(); + + $data['cards'][] = array( + 'text' => $this->language->get('text_mastercard'), + 'value' => 'mastercard' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_visa'), + 'value' => 'visa' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_diners'), + 'value' => 'diners' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_amex'), + 'value' => 'amex' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_maestro'), + 'value' => 'maestro' + ); + + if (isset($this->request->post['firstdata_remote_cards_accepted'])) { + $data['firstdata_remote_cards_accepted'] = $this->request->post['firstdata_remote_cards_accepted']; + } elseif ($this->config->get('firstdata_remote_cards_accepted')) { + $data['firstdata_remote_cards_accepted'] = $this->config->get('firstdata_remote_cards_accepted'); + } else { + $data['firstdata_remote_cards_accepted'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/firstdata_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/firstdata_remote'); + $this->model_extension_payment_firstdata_remote->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/firstdata_remote'); + $this->model_extension_payment_firstdata_remote->uninstall(); + } + + public function order() { + if ($this->config->get('firstdata_remote_status')) { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->get['order_id']); + + if (!empty($firstdata_order)) { + $this->load->language('extension/payment/firstdata_remote'); + + $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true); + $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true); + + $data['firstdata_order'] = $firstdata_order; + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_ref'] = $this->language->get('text_order_ref'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_refund_status'] = $this->language->get('text_refund_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_yes'] = $this->language->get('text_yes'); + $data['text_no'] = $this->language->get('text_no'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_date_added'] = $this->language->get('text_column_date_added'); + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + + $data['button_capture'] = $this->language->get('button_capture'); + $data['button_refund'] = $this->language->get('button_refund'); + $data['button_void'] = $this->language->get('button_void'); + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/firstdata_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/firstdata_remote'); + + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_firstdata_remote->void($firstdata_order['order_ref'], $firstdata_order['tdate']); + + $this->model_extension_payment_firstdata_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (strtoupper($void_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'void', 0.00); + + $this->model_extension_payment_firstdata_remote->updateVoidStatus($firstdata_order['firstdata_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['column_date_added'] = date('Y-m-d H:i:s'); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['error']) && !empty($void_response['error']) ? (string)$void_response['error'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/firstdata'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_firstdata_remote->capture($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); + + $this->model_extension_payment_firstdata_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (strtoupper($capture_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'payment', $firstdata_order['total']); + $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + $this->model_extension_payment_firstdata_remote->updateCaptureStatus($firstdata_order['firstdata_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + $json['data'] = array(); + $json['data']['column_date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$firstdata_order['total']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $firstdata_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response['error']) && !empty($capture_response['error']) ? (string)$capture_response['error'] : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/firstdata_remote'); + + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_firstdata_remote->refund($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); + + $this->model_extension_payment_firstdata_remote->logger('Refund result:\r\n' . print_r($refund_response, 1)); + + if (strtoupper($refund_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'refund', $firstdata_order['total'] * -1); + + $total_refunded = $this->model_extension_payment_firstdata_remote->getTotalRefunded($firstdata_order['firstdata_remote_order_id']); + $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + if ($total_captured <= 0 && $firstdata_order['capture_status'] == 1) { + $this->model_extension_payment_firstdata_remote->updateRefundStatus($firstdata_order['firstdata_remote_order_id'], 1); + $refund_status = 1; + $json['msg'] = $this->language->get('text_refund_ok_order'); + } else { + $refund_status = 0; + $json['msg'] = $this->language->get('text_refund_ok'); + } + + $json['data'] = array(); + $json['data']['column_date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $firstdata_order['total'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_refunded'] = (float)$total_refunded; + $json['data']['refund_status'] = $refund_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($refund_response['error']) && !empty($refund_response['error']) ? (string)$refund_response['error'] : 'Unable to refund'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/firstdata_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['firstdata_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['firstdata_remote_user_id']) { + $this->error['error_user_id'] = $this->language->get('error_user_id'); + } + + if (!$this->request->post['firstdata_remote_password']) { + $this->error['error_password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['firstdata_remote_certificate']) { + $this->error['error_certificate'] = $this->language->get('error_certificate'); + } + + if (!$this->request->post['firstdata_remote_key']) { + $this->error['error_key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['firstdata_remote_key_pw']) { + $this->error['error_key_pw'] = $this->language->get('error_key_pw'); + } + + if (!$this->request->post['firstdata_remote_ca']) { + $this->error['error_ca'] = $this->language->get('error_ca'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/free_checkout.php b/public/admin/controller/extension/payment/free_checkout.php new file mode 100644 index 0000000..90578c5 --- /dev/null +++ b/public/admin/controller/extension/payment/free_checkout.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionPaymentFreeCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/free_checkout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_free_checkout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/free_checkout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/free_checkout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['free_checkout_order_status_id'])) { + $data['free_checkout_order_status_id'] = $this->request->post['free_checkout_order_status_id']; + } else { + $data['free_checkout_order_status_id'] = $this->config->get('free_checkout_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_free_checkout_status'])) { + $data['payment_free_checkout_status'] = $this->request->post['payment_free_checkout_status']; + } else { + $data['payment_free_checkout_status'] = $this->config->get('payment_free_checkout_status'); + } + + if (isset($this->request->post['payment_free_checkout_sort_order'])) { + $data['payment_free_checkout_sort_order'] = $this->request->post['payment_free_checkout_sort_order']; + } else { + $data['payment_free_checkout_sort_order'] = $this->config->get('payment_free_checkout_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/free_checkout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/free_checkout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/g2apay.php b/public/admin/controller/extension/payment/g2apay.php new file mode 100644 index 0000000..19014f5 --- /dev/null +++ b/public/admin/controller/extension/payment/g2apay.php @@ -0,0 +1,302 @@ +<?php + +class ControllerExtensionPaymentG2APay extends Controller { + + private $error = array(); + + public function index() { + $this->load->language('extension/payment/g2apay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_g2apay', $this->request->post); + + $this->session->data['complete'] = $this->language->get('text_complete'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['api_hash'])) { + $data['error_api_hash'] = $this->error['api_hash']; + } else { + $data['error_api_hash'] = ''; + } + + if (isset($this->request->post['payment_g2apay_order_status_id'])) { + $data['payment_g2apay_order_status_id'] = $this->request->post['payment_g2apay_order_status_id']; + } else { + $data['payment_g2apay_order_status_id'] = $this->config->get('payment_g2apay_order_status_id'); + } + + if (isset($this->request->post['payment_g2apay_complete_status_id'])) { + $data['payment_g2apay_complete_status_id'] = $this->request->post['payment_g2apay_complete_status_id']; + } else { + $data['payment_g2apay_complete_status_id'] = $this->config->get('payment_g2apay_complete_status_id'); + } + + if (isset($this->request->post['payment_g2apay_rejected_status_id'])) { + $data['payment_g2apay_rejected_status_id'] = $this->request->post['payment_g2apay_rejected_status_id']; + } else { + $data['payment_g2apay_rejected_status_id'] = $this->config->get('payment_g2apay_rejected_status_id'); + } + + if (isset($this->request->post['payment_g2apay_cancelled_status_id'])) { + $data['payment_g2apay_cancelled_status_id'] = $this->request->post['payment_g2apay_cancelled_status_id']; + } else { + $data['payment_g2apay_cancelled_status_id'] = $this->config->get('payment_g2apay_cancelled_status_id'); + } + + if (isset($this->request->post['payment_g2apay_pending_status_id'])) { + $data['payment_g2apay_pending_status_id'] = $this->request->post['payment_g2apay_pending_status_id']; + } else { + $data['payment_g2apay_pending_status_id'] = $this->config->get('payment_g2apay_pending_status_id'); + } + + if (isset($this->request->post['payment_g2apay_refunded_status_id'])) { + $data['payment_g2apay_refunded_status_id'] = $this->request->post['payment_g2apay_refunded_status_id']; + } else { + $data['payment_g2apay_refunded_status_id'] = $this->config->get('payment_g2apay_refunded_status_id'); + } + + if (isset($this->request->post['payment_g2apay_partially_refunded_status_id'])) { + $data['payment_g2apay_partially_refunded_status_id'] = $this->request->post['payment_g2apay_partially_refunded_status_id']; + } else { + $data['payment_g2apay_partially_refunded_status_id'] = $this->config->get('payment_g2apay_partially_refunded_status_id'); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/g2apay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['action'] = $this->url->link('extension/payment/g2apay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_g2apay_username'])) { + $data['payment_g2apay_username'] = $this->request->post['payment_g2apay_username']; + } else { + $data['payment_g2apay_username'] = $this->config->get('payment_g2apay_username'); + } + + if (isset($this->request->post['payment_g2apay_secret'])) { + $data['payment_g2apay_secret'] = $this->request->post['payment_g2apay_secret']; + } else { + $data['payment_g2apay_secret'] = $this->config->get('payment_g2apay_secret'); + } + + if (isset($this->request->post['payment_g2apay_api_hash'])) { + $data['payment_g2apay_api_hash'] = $this->request->post['payment_g2apay_api_hash']; + } else { + $data['payment_g2apay_api_hash'] = $this->config->get('payment_g2apay_api_hash'); + } + + if (isset($this->request->post['payment_g2apay_environment'])) { + $data['payment_g2apay_environment'] = $this->request->post['payment_g2apay_environment']; + } else { + $data['payment_g2apay_environment'] = $this->config->get('payment_g2apay_environment'); + } + + if (isset($this->request->post['payment_g2apay_total'])) { + $data['payment_g2apay_total'] = $this->request->post['payment_g2apay_total']; + } else { + $data['payment_g2apay_total'] = $this->config->get('payment_g2apay_total'); + } + + if (isset($this->request->post['payment_g2apay_secret_token'])) { + $data['payment_g2apay_secret_token'] = $this->request->post['payment_g2apay_secret_token']; + } elseif ($this->config->get('payment_g2apay_secret_token')) { + $data['payment_g2apay_secret_token'] = $this->config->get('payment_g2apay_secret_token'); + } else { + $data['payment_g2apay_secret_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['g2apay_ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/g2apay/ipn&token=' . $data['payment_g2apay_secret_token']; + + if (isset($this->request->post['payment_g2apay_ipn_uri'])) { + $data['payment_g2apay_ipn_uri'] = $this->request->post['payment_g2apay_ipn_uri']; + } else { + $data['payment_g2apay_ipn_uri'] = $this->config->get('payment_g2apay_ipn_uri'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_g2apay_geo_zone_id'])) { + $data['payment_g2apay_geo_zone_id'] = $this->request->post['payment_g2apay_geo_zone_id']; + } else { + $data['payment_g2apay_geo_zone_id'] = $this->config->get('payment_g2apay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_g2apay_status'])) { + $data['payment_g2apay_status'] = $this->request->post['payment_g2apay_status']; + } else { + $data['payment_g2apay_status'] = $this->config->get('payment_g2apay_status'); + } + + if (isset($this->request->post['payment_g2apay_debug'])) { + $data['payment_g2apay_debug'] = $this->request->post['payment_g2apay_debug']; + } else { + $data['payment_g2apay_debug'] = $this->config->get('payment_g2apay_debug'); + } + + if (isset($this->request->post['payment_g2apay_sort_order'])) { + $data['payment_g2apay_sort_order'] = $this->request->post['payment_g2apay_sort_order']; + } else { + $data['payment_g2apay_sort_order'] = $this->config->get('payment_g2apay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/g2apay', $data)); + } + + public function order() { + + if ($this->config->get('payment_g2apay_status')) { + + $this->load->model('extension/payment/g2apay'); + + $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->get['order_id']); + + if (!empty($g2apay_order)) { + $this->load->language('extension/payment/g2apay'); + + $g2apay_order['total_released'] = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']); + + $g2apay_order['total_formatted'] = $this->currency->format($g2apay_order['total'], $g2apay_order['currency_code'], false); + $g2apay_order['total_released_formatted'] = $this->currency->format($g2apay_order['total_released'], $g2apay_order['currency_code'], false); + + $data['g2apay_order'] = $g2apay_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/g2apay_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/g2apay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/g2apay'); + + $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_g2apay->refund($g2apay_order, $this->request->post['amount']); + + $this->model_extension_payment_g2apay->logger($refund_response); + + if ($refund_response == 'ok') { + $this->model_extension_payment_g2apay->addTransaction($g2apay_order['g2apay_order_id'], 'refund', $this->request->post['amount'] * -1); + + $total_refunded = $this->model_extension_payment_g2apay->getTotalRefunded($g2apay_order['g2apay_order_id']); + $total_released = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']); + + if ($total_released <= 0 && $g2apay_order['release_status'] == 1) { + $this->model_extension_payment_g2apay->updateRefundStatus($g2apay_order['g2apay_order_id'], 1); + $refund_status = 1; + $json['msg'] = $this->language->get('text_refund_ok_order'); + } else { + $refund_status = 0; + $json['msg'] = $this->language->get('text_refund_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $g2apay_order['currency_code'], false); + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_refunded'] = (float)$total_refunded; + $json['data']['refund_status'] = $refund_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = 'Unable to refund: ' . $refund_response; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function install() { + $this->load->model('extension/payment/g2apay'); + $this->model_extension_payment_g2apay->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/g2apay'); + $this->model_extension_payment_g2apay->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/g2apay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_g2apay_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_g2apay_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_g2apay_api_hash']) { + $this->error['api_hash'] = $this->language->get('error_api_hash'); + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/globalpay.php b/public/admin/controller/extension/payment/globalpay.php new file mode 100644 index 0000000..4e833d6 --- /dev/null +++ b/public/admin/controller/extension/payment/globalpay.php @@ -0,0 +1,408 @@ +<?php +class ControllerExtensionPaymentGlobalpay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/globalpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_globalpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/globalpay/notify'; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/globalpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/globalpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_globalpay_merchant_id'])) { + $data['payment_globalpay_merchant_id'] = $this->request->post['payment_globalpay_merchant_id']; + } else { + $data['payment_globalpay_merchant_id'] = $this->config->get('payment_globalpay_merchant_id'); + } + + if (isset($this->request->post['payment_globalpay_secret'])) { + $data['payment_globalpay_secret'] = $this->request->post['payment_globalpay_secret']; + } else { + $data['payment_globalpay_secret'] = $this->config->get('payment_globalpay_secret'); + } + + if (isset($this->request->post['payment_globalpay_rebate_password'])) { + $data['payment_globalpay_rebate_password'] = $this->request->post['payment_globalpay_rebate_password']; + } else { + $data['payment_globalpay_rebate_password'] = $this->config->get('payment_globalpay_rebate_password'); + } + + if (isset($this->request->post['payment_globalpay_live_demo'])) { + $data['payment_globalpay_live_demo'] = $this->request->post['payment_globalpay_live_demo']; + } else { + $data['payment_globalpay_live_demo'] = $this->config->get('payment_globalpay_live_demo'); + } + + if (isset($this->request->post['payment_globalpay_geo_zone_id'])) { + $data['payment_globalpay_geo_zone_id'] = $this->request->post['payment_globalpay_geo_zone_id']; + } else { + $data['payment_globalpay_geo_zone_id'] = $this->config->get('payment_globalpay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_globalpay_total'])) { + $data['payment_globalpay_total'] = $this->request->post['payment_globalpay_total']; + } else { + $data['payment_globalpay_total'] = $this->config->get('payment_globalpay_total'); + } + + if (isset($this->request->post['payment_globalpay_sort_order'])) { + $data['payment_globalpay_sort_order'] = $this->request->post['payment_globalpay_sort_order']; + } else { + $data['payment_globalpay_sort_order'] = $this->config->get('payment_globalpay_sort_order'); + } + + if (isset($this->request->post['payment_globalpay_status'])) { + $data['payment_globalpay_status'] = $this->request->post['payment_globalpay_status']; + } else { + $data['payment_globalpay_status'] = $this->config->get('payment_globalpay_status'); + } + + if (isset($this->request->post['payment_globalpay_debug'])) { + $data['payment_globalpay_debug'] = $this->request->post['payment_globalpay_debug']; + } else { + $data['payment_globalpay_debug'] = $this->config->get('payment_globalpay_debug'); + } + + if (isset($this->request->post['payment_globalpay_account'])) { + $data['payment_globalpay_account'] = $this->request->post['payment_globalpay_account']; + } else { + $data['payment_globalpay_account'] = $this->config->get('payment_globalpay_account'); + } + + if (isset($this->request->post['payment_globalpay_auto_settle'])) { + $data['payment_globalpay_auto_settle'] = $this->request->post['payment_globalpay_auto_settle']; + } else { + $data['payment_globalpay_auto_settle'] = $this->config->get('payment_globalpay_auto_settle'); + } + + if (isset($this->request->post['payment_globalpay_card_select'])) { + $data['payment_globalpay_card_select'] = $this->request->post['payment_globalpay_card_select']; + } else { + $data['payment_globalpay_card_select'] = $this->config->get('payment_globalpay_card_select'); + } + + if (isset($this->request->post['payment_globalpay_tss_check'])) { + $data['payment_globalpay_tss_check'] = $this->request->post['payment_globalpay_tss_check']; + } else { + $data['payment_globalpay_tss_check'] = $this->config->get('payment_globalpay_tss_check'); + } + + if (isset($this->request->post['globalpay_order_status_success_settled_id'])) { + $data['globalpay_order_status_success_settled_id'] = $this->request->post['globalpay_order_status_success_settled_id']; + } else { + $data['globalpay_order_status_success_settled_id'] = $this->config->get('globalpay_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_success_unsettled_id'])) { + $data['payment_globalpay_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_order_status_success_unsettled_id']; + } else { + $data['payment_globalpay_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_id'])) { + $data['payment_globalpay_order_status_decline_id'] = $this->request->post['payment_globalpay_order_status_decline_id']; + } else { + $data['payment_globalpay_order_status_decline_id'] = $this->config->get('payment_globalpay_order_status_decline_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_pending_id'])) { + $data['payment_globalpay_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_order_status_decline_pending_id']; + } else { + $data['payment_globalpay_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_stolen_id'])) { + $data['payment_globalpay_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_order_status_decline_stolen_id']; + } else { + $data['payment_globalpay_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_bank_id'])) { + $data['payment_globalpay_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_order_status_decline_bank_id']; + } else { + $data['payment_globalpay_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_globalpay_live_url'])) { + $data['payment_globalpay_live_url'] = $this->request->post['payment_globalpay_live_url']; + } else { + $data['payment_globalpay_live_url'] = $this->config->get('payment_globalpay_live_url'); + } + + if (empty($data['payment_globalpay_live_url'])) { + $data['payment_globalpay_live_url'] = 'https://hpp.globaliris.com/pay'; + } + + if (isset($this->request->post['payment_globalpay_demo_url'])) { + $data['payment_globalpay_demo_url'] = $this->request->post['payment_globalpay_demo_url']; + } else { + $data['payment_globalpay_demo_url'] = $this->config->get('payment_globalpay_demo_url'); + } + + if (empty($data['payment_globalpay_demo_url'])) { + $data['payment_globalpay_demo_url'] = 'https://hpp.sandbox.globaliris.com/pay'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/globalpay', $data)); + } + + public function install() { + $this->load->model('extension/payment/globalpay'); + + $this->model_extension_payment_globalpay->install(); + } + + public function order() { + if ($this->config->get('payment_globalpay_status')) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->get['order_id']); + + if (!empty($globalpay_order)) { + $this->load->language('extension/payment/globalpay'); + + $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true); + $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true); + + $data['globalpay_order'] = $globalpay_order; + + $data['auto_settle'] = $globalpay_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/globalpay_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_globalpay->void($this->request->post['order_id']); + + $this->model_extension_payment_globalpay->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'void', 0.00); + $this->model_extension_payment_globalpay->updateVoidStatus($globalpay_order['globalpay_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_globalpay->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'payment', $this->request->post['amount']); + + $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) { + $this->model_extension_payment_globalpay->updateCaptureStatus($globalpay_order['globalpay_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_globalpay->updateForRebate($globalpay_order['globalpay_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_globalpay->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_globalpay->getTotalRebated($globalpay_order['globalpay_order_id']); + $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) { + $this->model_extension_payment_globalpay->updateRebateStatus($globalpay_order['globalpay_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']*-1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/globalpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_globalpay_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_globalpay_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_globalpay_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_globalpay_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/globalpay_remote.php b/public/admin/controller/extension/payment/globalpay_remote.php new file mode 100644 index 0000000..c4e69c3 --- /dev/null +++ b/public/admin/controller/extension/payment/globalpay_remote.php @@ -0,0 +1,372 @@ +<?php +class ControllerExtensionPaymentGlobalpayRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/globalpay_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_globalpay_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/globalpay_remote', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/globalpay_remote', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_globalpay_remote_merchant_id'])) { + $data['payment_globalpay_remote_merchant_id'] = $this->request->post['payment_globalpay_remote_merchant_id']; + } else { + $data['payment_globalpay_remote_merchant_id'] = $this->config->get('payment_globalpay_remote_merchant_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_secret'])) { + $data['payment_globalpay_remote_secret'] = $this->request->post['payment_globalpay_remote_secret']; + } else { + $data['payment_globalpay_remote_secret'] = $this->config->get('payment_globalpay_remote_secret'); + } + + if (isset($this->request->post['payment_globalpay_remote_rebate_password'])) { + $data['payment_globalpay_remote_rebate_password'] = $this->request->post['payment_globalpay_remote_rebate_password']; + } else { + $data['payment_globalpay_remote_rebate_password'] = $this->config->get('payment_globalpay_remote_rebate_password'); + } + + if (isset($this->request->post['payment_globalpay_remote_geo_zone_id'])) { + $data['payment_globalpay_remote_geo_zone_id'] = $this->request->post['payment_globalpay_remote_geo_zone_id']; + } else { + $data['payment_globalpay_remote_geo_zone_id'] = $this->config->get('payment_globalpay_remote_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_globalpay_remote_total'])) { + $data['payment_globalpay_remote_total'] = $this->request->post['payment_globalpay_remote_total']; + } else { + $data['payment_globalpay_remote_total'] = $this->config->get('payment_globalpay_remote_total'); + } + + if (isset($this->request->post['payment_globalpay_remote_sort_order'])) { + $data['payment_globalpay_remote_sort_order'] = $this->request->post['payment_globalpay_remote_sort_order']; + } else { + $data['payment_globalpay_remote_sort_order'] = $this->config->get('payment_globalpay_remote_sort_order'); + } + + if (isset($this->request->post['payment_globalpay_remote_status'])) { + $data['payment_globalpay_remote_status'] = $this->request->post['payment_globalpay_remote_status']; + } else { + $data['payment_globalpay_remote_status'] = $this->config->get('payment_globalpay_remote_status'); + } + + if (isset($this->request->post['payment_globalpay_remote_card_data_status'])) { + $data['payment_globalpay_remote_card_data_status'] = $this->request->post['payment_globalpay_remote_card_data_status']; + } else { + $data['payment_globalpay_remote_card_data_status'] = $this->config->get('payment_globalpay_remote_card_data_status'); + } + + if (isset($this->request->post['payment_globalpay_remote_debug'])) { + $data['payment_globalpay_remote_debug'] = $this->request->post['payment_globalpay_remote_debug']; + } else { + $data['payment_globalpay_remote_debug'] = $this->config->get('payment_globalpay_remote_debug'); + } + + if (isset($this->request->post['payment_globalpay_remote_account'])) { + $data['payment_globalpay_remote_account'] = $this->request->post['payment_globalpay_remote_account']; + } else { + $data['payment_globalpay_remote_account'] = $this->config->get('payment_globalpay_remote_account'); + } + + if (isset($this->request->post['payment_globalpay_remote_auto_settle'])) { + $data['payment_globalpay_remote_auto_settle'] = $this->request->post['payment_globalpay_remote_auto_settle']; + } else { + $data['payment_globalpay_remote_auto_settle'] = $this->config->get('payment_globalpay_remote_auto_settle'); + } + + if (isset($this->request->post['payment_globalpay_remote_tss_check'])) { + $data['payment_globalpay_remote_tss_check'] = $this->request->post['payment_globalpay_remote_tss_check']; + } else { + $data['payment_globalpay_remote_tss_check'] = $this->config->get('payment_globalpay_remote_tss_check'); + } + + if (isset($this->request->post['payment_globalpay_remote_3d'])) { + $data['payment_globalpay_remote_3d'] = $this->request->post['payment_globalpay_remote_3d']; + } else { + $data['payment_globalpay_remote_3d'] = $this->config->get('payment_globalpay_remote_3d'); + } + + if (isset($this->request->post['payment_globalpay_remote_liability'])) { + $data['payment_globalpay_remote_liability'] = $this->request->post['payment_globalpay_remote_liability']; + } else { + $data['payment_globalpay_remote_liability'] = $this->config->get('payment_globalpay_remote_liability'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_success_settled_id'])) { + $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_settled_id']; + } else { + $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_success_unsettled_id'])) { + $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_unsettled_id']; + } else { + $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_id'])) { + $data['payment_globalpay_remote_order_status_decline_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_pending_id'])) { + $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_pending_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_stolen_id'])) { + $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_stolen_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_bank_id'])) { + $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_bank_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/globalpay_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/globalpay_remote'); + $this->model_extension_payment_globalpay_remote->install(); + } + + public function order() { + if ($this->config->get('payment_globalpay_remote_status')) { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->get['order_id']); + + if (!empty($globalpay_order)) { + $this->load->language('extension/payment/globalpay_remote'); + + $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true); + $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true); + + $data['globalpay_order'] = $globalpay_order; + + $data['auto_settle'] = $globalpay_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/globalpay_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/globalpay_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_globalpay_remote->void($this->request->post['order_id']); + + $this->model_extension_payment_globalpay_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'void', 0.00); + $this->model_extension_payment_globalpay_remote->updateVoidStatus($globalpay_order['globalpay_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_globalpay_remote->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'payment', $this->request->post['amount']); + $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) { + $this->model_extension_payment_globalpay_remote->updateCaptureStatus($globalpay_order['globalpay_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_globalpay_remote->updateForRebate($globalpay_order['globalpay_remote_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $globalpay_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/globalpay_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_globalpay_remote->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_globalpay_remote->getTotalRebated($globalpay_order['globalpay_remote_order_id']); + $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) { + $this->model_extension_payment_globalpay_remote->updateRebateStatus($globalpay_order['globalpay_remote_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/globalpay_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_globalpay_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_globalpay_remote_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_account.php b/public/admin/controller/extension/payment/klarna_account.php new file mode 100644 index 0000000..30dff8b --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_account.php @@ -0,0 +1,329 @@ +<?php +class ControllerExtensionPaymentKlarnaAccount extends Controller { + private $error = array(); + private $pclasses = array(); + + public function index() { + $this->load->language('extension/payment/klarna_account'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['payment_klarna_account_'] as $klarna_account) { + if ($klarna_account['status']) { + $status = true; + + break; + } + } + + $klarna_data = array( + 'klarna_account_pclasses' => $this->pclasses, + 'klarna_account_status' => $status + ); + + $this->model_setting_setting->editSetting('payment_klarna_account', array_merge($this->request->post, $klarna_data)); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + 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'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['payment_klarna_account'])) { + $data['payment_klarna_account'] = $this->request->post['payment_klarna_account']; + } else { + $data['payment_klarna_account'] = $this->config->get('payment_klarna_account'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $file = DIR_LOGS . 'klarna_account.log'; + + if (file_exists($file)) { + $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null); + } else { + $data['log'] = ''; + } + + $data['clear'] = $this->url->link('extension/payment/klarna_account/clear', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_account', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_account')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $log = new Log('klarna_account.log'); + + $country = array( + 'NOR' => array( + 'currency' => 1, + 'country' => 164, + 'language' => 97, + ), + 'SWE' => array( + 'currency' => 0, + 'country' => 209, + 'language' => 138, + ), + 'FIN' => array( + 'currency' => 2, + 'country' => 73, + 'language' => 101, + ), + 'DNK' => array( + 'currency' => 3, + 'country' => 59, + 'language' => 27, + ), + 'DEU' => array( + 'currency' => 2, + 'country' => 81, + 'language' => 28, + ), + 'NLD' => array( + 'currency' => 2, + 'country' => 154, + 'language' => 101, + ), + ); + + foreach ($this->request->post['klarna_account'] as $key => $klarna_account) { + if ($klarna_account['status']) { + $digest = base64_encode(pack("H*", hash('sha256', $klarna_account['merchant'] . ':' . $country[$key]['currency'] . ':' . $klarna_account['secret']))); + + $xml = '<methodCall>'; + $xml .= ' <methodName>get_pclasses</methodName>'; + $xml .= ' <params>'; + $xml .= ' <param><value><string>4.1</string></value></param>'; + $xml .= ' <param><value><string>API:OPENCART:' . VERSION . '</string></value></param>'; + $xml .= ' <param><value><int>' . (int)$klarna_account['merchant'] . '</int></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['currency'] . '</int></value></param>'; + $xml .= ' <param><value><string>' . $digest . '</string></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['country'] . '</int></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['language'] . '</int></value></param>'; + $xml .= ' </params>'; + $xml .= '</methodCall>'; + + if ($klarna_account['server'] == 'live') { + $url = 'https://payment.klarna.com'; + } else { + $url = 'https://payment.testdrive.klarna.com'; + } + + $curl = curl_init(); + + $header = array(); + + $header[] = 'Content-Type: text/xml'; + $header[] = 'Content-Length: ' . strlen($xml); + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); + + $response = curl_exec($curl); + + if ($response !== false) { + $xml = new DOMDocument(); + $xml->loadXML($response); + + $xpath = new DOMXPath($xml); + + $nodes = $xpath->query('//methodResponse/params/param/value'); + + if ($nodes->length == 0) { + $this->error['warning'] = $this->language->get('error_log'); + + $error_code = $xpath->query('//methodResponse/fault/value/struct/member/value/int')->item(0)->nodeValue; + $error_message = $xpath->query('//methodResponse/fault/value/struct/member/value/string')->item(0)->nodeValue; + + $log->write(sprintf($this->language->get('error_pclass'), $key, $error_code, $error_message)); + + continue; + } + + $pclasses = $this->parseResponse($nodes->item(0)->firstChild, $xml); + + while ($pclasses) { + $pclass = array_slice($pclasses, 0, 10); + $pclasses = array_slice($pclasses, 10); + + $pclass[3] /= 100; + $pclass[4] /= 100; + $pclass[5] /= 100; + $pclass[6] /= 100; + $pclass[9] = ($pclass[9] != '-') ? strtotime($pclass[9]) : $pclass[9]; + + array_unshift($pclass, $klarna_account['merchant']); + + $this->pclasses[$key][] = array( + 'eid' => intval($pclass[0]), + 'id' => intval($pclass[1]), + 'description' => $pclass[2], + 'months' => intval($pclass[3]), + 'startfee' => floatval($pclass[4]), + 'invoicefee' => floatval($pclass[5]), + 'interestrate' => floatval($pclass[6]), + 'minamount' => floatval($pclass[7]), + 'country' => intval($pclass[8]), + 'type' => intval($pclass[9]), + ); + } + } else { + $this->error['warning'] = $this->language->get('error_log'); + + $log->write(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl))); + } + + curl_close($curl); + } + } + + return !$this->error; + } + + private function parseResponse($node, $document) { + $child = $node; + + switch ($child->nodeName) { + case 'string': + $value = $child->nodeValue; + break; + case 'boolean': + $value = (string)$child->nodeValue; + + if ($value == '0') { + $value = false; + } elseif ($value == '1') { + $value = true; + } else { + $value = null; + } + + break; + case 'integer': + case 'int': + case 'i4': + case 'i8': + $value = (int)$child->nodeValue; + break; + case 'array': + $value = array(); + + $xpath = new DOMXPath($document); + $entries = $xpath->query('.//array/data/value', $child); + + for ($i = 0; $i < $entries->length; $i++) { + $value[] = $this->parseResponse($entries->item($i)->firstChild, $document); + } + + break; + default: + $value = null; + } + + return $value; + } + + public function clear() { + $this->load->language('extension/payment/klarna_account'); + + $file = DIR_LOGS . 'klarna_account.log'; + + $handle = fopen($file, 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_checkout.php b/public/admin/controller/extension/payment/klarna_checkout.php new file mode 100644 index 0000000..edeb9c4 --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_checkout.php @@ -0,0 +1,859 @@ +<?php +class ControllerExtensionPaymentKlarnaCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_klarna_checkout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['api_locations'] = array( + array( + 'name' => 'North America', + 'code' => 'NA' + ), + array( + 'name' => 'Europe', + 'code' => 'EU' + ) + ); + + $this->load->model('catalog/information'); + + $data['informations'] = $this->model_catalog_information->getInformations(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $this->load->model('extension/payment/klarna_checkout'); + + if ($this->model_extension_payment_klarna_checkout->checkForPaymentTaxes()) { + $data['error_tax_warning'] = $this->language->get('error_tax_warning'); + } else { + $data['error_tax_warning'] = ''; + } + + if (isset($this->error['account_warning'])) { + $data['error_account_warning'] = $this->error['account_warning']; + } else { + $data['error_account_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = array(); + } + + if (isset($this->error['settlement_warning'])) { + $data['error_settlement_warning'] = $this->error['settlement_warning']; + } else { + $data['error_settlement_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_checkout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_checkout', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['klarna_checkout_debug'])) { + $data['klarna_checkout_debug'] = $this->request->post['klarna_checkout_debug']; + } else { + $data['klarna_checkout_debug'] = $this->config->get('klarna_checkout_debug'); + } + + if (isset($this->request->post['klarna_checkout_colour_button'])) { + $data['klarna_checkout_colour_button'] = $this->request->post['klarna_checkout_colour_button']; + } elseif ($this->config->get('klarna_checkout_colour_button')) { + $data['klarna_checkout_colour_button'] = $this->config->get('klarna_checkout_colour_button'); + } else { + $data['klarna_checkout_colour_button'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_colour_button_text'])) { + $data['klarna_checkout_colour_button_text'] = $this->request->post['klarna_checkout_colour_button_text']; + } elseif ($this->config->get('klarna_checkout_colour_button_text')) { + $data['klarna_checkout_colour_button_text'] = $this->config->get('klarna_checkout_colour_button_text'); + } else { + $data['klarna_checkout_colour_button_text'] = '#ffffff'; + } + + if (isset($this->request->post['klarna_checkout_colour_checkbox'])) { + $data['klarna_checkout_colour_checkbox'] = $this->request->post['klarna_checkout_colour_checkbox']; + } elseif ($this->config->get('klarna_checkout_colour_checkbox')) { + $data['klarna_checkout_colour_checkbox'] = $this->config->get('klarna_checkout_colour_checkbox'); + } else { + $data['klarna_checkout_colour_checkbox'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_colour_checkbox_checkmark'])) { + $data['klarna_checkout_colour_checkbox_checkmark'] = $this->request->post['klarna_checkout_colour_checkbox_checkmark']; + } elseif ($this->config->get('klarna_checkout_colour_checkbox_checkmark')) { + $data['klarna_checkout_colour_checkbox_checkmark'] = $this->config->get('klarna_checkout_colour_checkbox_checkmark'); + } else { + $data['klarna_checkout_colour_checkbox_checkmark'] = '#ffffff'; + } + + if (isset($this->request->post['klarna_checkout_colour_header'])) { + $data['klarna_checkout_colour_header'] = $this->request->post['klarna_checkout_colour_header']; + } elseif ($this->config->get('klarna_checkout_colour_header')) { + $data['klarna_checkout_colour_header'] = $this->config->get('klarna_checkout_colour_header'); + } else { + $data['klarna_checkout_colour_header'] = '#434343'; + } + + if (isset($this->request->post['klarna_checkout_colour_link'])) { + $data['klarna_checkout_colour_link'] = $this->request->post['klarna_checkout_colour_link']; + } elseif ($this->config->get('klarna_checkout_colour_link')) { + $data['klarna_checkout_colour_link'] = $this->config->get('klarna_checkout_colour_link'); + } else { + $data['klarna_checkout_colour_link'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_separate_shipping_address'])) { + $data['klarna_checkout_separate_shipping_address'] = $this->request->post['klarna_checkout_separate_shipping_address']; + } else { + $data['klarna_checkout_separate_shipping_address'] = $this->config->get('klarna_checkout_separate_shipping_address'); + } + + if (isset($this->request->post['klarna_checkout_dob_mandatory'])) { + $data['klarna_checkout_dob_mandatory'] = $this->request->post['klarna_checkout_dob_mandatory']; + } else { + $data['klarna_checkout_dob_mandatory'] = $this->config->get('klarna_checkout_dob_mandatory'); + } + + if (isset($this->request->post['klarna_checkout_title_mandatory'])) { + $data['klarna_checkout_title_mandatory'] = $this->request->post['klarna_checkout_title_mandatory']; + } else { + $data['klarna_checkout_title_mandatory'] = $this->config->get('klarna_checkout_title_mandatory'); + } + + if (isset($this->request->post['klarna_checkout_additional_text_box'])) { + $data['klarna_checkout_additional_text_box'] = $this->request->post['klarna_checkout_additional_text_box']; + } else { + $data['klarna_checkout_additional_text_box'] = $this->config->get('klarna_checkout_additional_text_box'); + } + + if (isset($this->request->post['klarna_checkout_total'])) { + $data['klarna_checkout_total'] = $this->request->post['klarna_checkout_total']; + } else { + $data['klarna_checkout_total'] = $this->config->get('klarna_checkout_total'); + } + + if (isset($this->request->post['klarna_checkout_order_status_authorised_id'])) { + $data['klarna_checkout_order_status_authorised_id'] = $this->request->post['klarna_checkout_order_status_authorised_id']; + } else { + $data['klarna_checkout_order_status_authorised_id'] = $this->config->get('klarna_checkout_order_status_authorised_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_part_captured_id'])) { + $data['klarna_checkout_order_status_part_captured_id'] = $this->request->post['klarna_checkout_order_status_part_captured_id']; + } else { + $data['klarna_checkout_order_status_part_captured_id'] = $this->config->get('klarna_checkout_order_status_part_captured_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_captured_id'])) { + $data['klarna_checkout_order_status_captured_id'] = $this->request->post['klarna_checkout_order_status_captured_id']; + } else { + $data['klarna_checkout_order_status_captured_id'] = $this->config->get('klarna_checkout_order_status_captured_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_cancelled_id'])) { + $data['klarna_checkout_order_status_cancelled_id'] = $this->request->post['klarna_checkout_order_status_cancelled_id']; + } else { + $data['klarna_checkout_order_status_cancelled_id'] = $this->config->get('klarna_checkout_order_status_cancelled_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_refund_id'])) { + $data['klarna_checkout_order_status_refund_id'] = $this->request->post['klarna_checkout_order_status_refund_id']; + } else { + $data['klarna_checkout_order_status_refund_id'] = $this->config->get('klarna_checkout_order_status_refund_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_rejected_id'])) { + $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->request->post['klarna_checkout_order_status_fraud_rejected_id']; + } else { + $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->config->get('klarna_checkout_order_status_fraud_rejected_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_pending_id'])) { + $data['klarna_checkout_order_status_fraud_pending_id'] = $this->request->post['klarna_checkout_order_status_fraud_pending_id']; + } else { + $data['klarna_checkout_order_status_fraud_pending_id'] = $this->config->get('klarna_checkout_order_status_fraud_pending_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_accepted_id'])) { + $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->request->post['klarna_checkout_order_status_fraud_accepted_id']; + } else { + $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->config->get('klarna_checkout_order_status_fraud_accepted_id'); + } + + if (isset($this->request->post['klarna_checkout_terms'])) { + $data['klarna_checkout_terms'] = $this->request->post['klarna_checkout_terms']; + } else { + $data['klarna_checkout_terms'] = $this->config->get('klarna_checkout_terms'); + } + + if (isset($this->request->post['klarna_checkout_status'])) { + $data['klarna_checkout_status'] = $this->request->post['klarna_checkout_status']; + } else { + $data['klarna_checkout_status'] = $this->config->get('klarna_checkout_status'); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post['klarna_checkout_account'])) { + $data['klarna_checkout_account'] = array(); + } elseif ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['klarna_checkout_account'])) { + $data['klarna_checkout_account'] = $this->request->post['klarna_checkout_account']; + } elseif ($this->config->get('klarna_checkout_account')) { + $data['klarna_checkout_account'] = $this->config->get('klarna_checkout_account'); + } else { + $data['klarna_checkout_account'] = array(); + } + + if (isset($this->request->post['klarna_checkout_sftp_username'])) { + $data['klarna_checkout_sftp_username'] = $this->request->post['klarna_checkout_sftp_username']; + } else { + $data['klarna_checkout_sftp_username'] = $this->config->get('klarna_checkout_sftp_username'); + } + + if (isset($this->request->post['klarna_checkout_sftp_password'])) { + $data['klarna_checkout_sftp_password'] = $this->request->post['klarna_checkout_sftp_password']; + } else { + $data['klarna_checkout_sftp_password'] = $this->config->get('klarna_checkout_sftp_password'); + } + + if (isset($this->request->post['klarna_checkout_settlement_order_status_id'])) { + $data['klarna_checkout_settlement_order_status_id'] = $this->request->post['klarna_checkout_settlement_order_status_id']; + } else { + $data['klarna_checkout_settlement_order_status_id'] = $this->config->get('klarna_checkout_settlement_order_status_id'); + } + + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info) { + $data['api_id'] = $api_info['api_id']; + $data['api_key'] = $api_info['key']; + $data['api_ip'] = $this->request->server['REMOTE_ADDR']; + } else { + $data['api_id'] = ''; + $data['api_key'] = ''; + $data['api_ip'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_checkout', $data)); + } + + public function order() { + $this->load->language('extension/payment/klarna_checkout'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/klarna_checkout_order', $data); + } + + public function getTransaction() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + if (!$this->config->get('klarna_checkout_status') || !isset($this->request->get['order_id'])) { + return; + } + + $order_reference = $this->model_extension_payment_klarna_checkout->getOrder($this->request->get['order_id']); + + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + + if (!$order_reference || !$order_reference['order_ref'] || !$order_info) { + return; + } + + list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']); + + if (!$klarna_account || !$connector) { + return; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $order_reference['order_ref']); + + if (!$klarna_order) { + return; + } + + $data['order_ref'] = $order_reference['order_ref']; + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $extend_authorization_action = $cancel_action = $capture_action = $refund_action = $merchant_reference_action = $address_action = $release_authorization_action = false; + + switch (strtoupper($klarna_order['status'])) { + case 'AUTHORIZED': + $merchant_reference_action = true; + $extend_authorization_action = true; + $address_action = true; + $cancel_action = true; + $capture_action = true; + break; + case 'PART_CAPTURED': + $merchant_reference_action = true; + $extend_authorization_action = true; + $release_authorization_action = true; + $address_action = true; + $capture_action = true; + $refund_action = true; + break; + case 'CAPTURED': + $address_action = true; + $merchant_reference_action = true; + $refund_action = true; + break; + case 'CANCELLED': + break; + case 'EXPIRED': + break; + case 'CLOSED': + break; + } + + $format = '{title} {given_name} {family_name}' . "\n" . '{street_address}' . "\n" . '{street_address2}' . "\n" . '{city} {postcode}' . "\n" . '{region}' . "\n" . '{country}' . "\n" . '{email} {phone}'; + + $find = array( + '{title}', + '{given_name}', + '{family_name}', + '{street_address}', + '{street_address2}', + '{city}', + '{postcode}', + '{region}', + '{country}', + '{email}', + '{phone}', + ); + + $replace = array( + 'title' => $klarna_order['billing_address']['title'], + 'given_name' => $klarna_order['billing_address']['given_name'], + 'family_name' => $klarna_order['billing_address']['family_name'], + 'street_address' => $klarna_order['billing_address']['street_address'], + 'street_address2' => $klarna_order['billing_address']['street_address2'], + 'city' => $klarna_order['billing_address']['city'], + 'postcode' => $klarna_order['billing_address']['postal_code'], + 'region' => $klarna_order['billing_address']['region'], + 'country' => $klarna_order['billing_address']['country'], + 'email' => $klarna_order['billing_address']['email'], + 'phone' => $klarna_order['billing_address']['phone'] + ); + + $billing_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $replace = array( + 'title' => $klarna_order['shipping_address']['title'], + 'given_name' => $klarna_order['shipping_address']['given_name'], + 'family_name' => $klarna_order['shipping_address']['family_name'], + 'street_address' => $klarna_order['shipping_address']['street_address'], + 'street_address2' => $klarna_order['shipping_address']['street_address2'], + 'city' => $klarna_order['shipping_address']['city'], + 'postcode' => $klarna_order['shipping_address']['postal_code'], + 'region' => $klarna_order['shipping_address']['region'], + 'country' => $klarna_order['shipping_address']['country'], + 'email' => $klarna_order['shipping_address']['email'], + 'phone' => $klarna_order['shipping_address']['phone'] + ); + + $shipping_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $order_lines = array(); + + foreach ($klarna_order['order_lines'] as $order_line) { + $order_lines[] = array( + 'reference' => $order_line['reference'], + 'type' => $order_line['type'], + 'quantity' => $order_line['quantity'], + 'quantity_unit' => $order_line['quantity_unit'], + 'name' => $order_line['name'], + 'total_amount' => $this->currency->format($order_line['total_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'unit_price' => $this->currency->format($order_line['unit_price'] / 100, $order_info['currency_code'], '1.00000000'), + 'total_discount_amount' => $this->currency->format($order_line['total_discount_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'tax_rate' => ($order_line['tax_rate'] / 100) . '%', + 'total_tax_amount' => $this->currency->format($order_line['total_tax_amount'] / 100, $order_info['currency_code'], '1.00000000') + ); + } + + $merchant_id = ''; + if ($order_reference['data']) { + $klarna_checkout_order_data = json_decode($this->encryption->decrypt($this->config->get('config_encryption'), $order_reference['data']), true); + if ($klarna_checkout_order_data && $klarna_checkout_order_data['merchant_id']) { + $merchant_id = $klarna_checkout_order_data['merchant_id']; + } + } + + $data['transaction'] = array( + 'order_id' => $klarna_order['order_id'], + 'merchant_id' => $merchant_id, + 'reference' => $klarna_order['klarna_reference'], + 'status' => $klarna_order['status'], + 'fraud_status' => $klarna_order['fraud_status'], + 'merchant_reference_1' => $klarna_order['merchant_reference1'], + 'billing_address' => $klarna_order['billing_address'], + 'shipping_address' => $klarna_order['shipping_address'], + 'billing_address_formatted' => $billing_address_formatted, + 'shipping_address_formatted' => $shipping_address_formatted, + 'order_lines' => $order_lines, + 'amount' => $this->currency->format($klarna_order['order_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'authorization_expiry' => isset($klarna_order['expires_at']) ? date($this->language->get('date_format_short'), strtotime($klarna_order['expires_at'])) : '', + 'authorization_remaining' => $this->currency->format($klarna_order['remaining_authorized_amount'] / 100, $order_info['currency_code'], '1.00000000'), + ); + + $max_capture_amount = $klarna_order['remaining_authorized_amount'] / 100; + + $max_refund_amount = $klarna_order['captured_amount'] / 100; + + $data['captures'] = array(); + + foreach ($klarna_order['captures'] as $capture) { + $data['captures'][] = array( + 'capture_id' => $capture['capture_id'], + 'shipping_info_title' => sprintf($this->language->get('text_capture_shipping_info_title'), $capture['capture_id']), + 'billing_address_title' => sprintf($this->language->get('text_capture_billing_address_title'), $capture['capture_id']), + 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['captured_at'])), + 'amount' => $this->currency->format($capture['captured_amount'] / 100, $order_info['currency_code'], '1.00000000', true), + 'reference' => $capture['klarna_reference'], + 'shipping_info' => $capture['shipping_info'], + 'billing_address' => $capture['billing_address'], + 'shipping_address' => $capture['shipping_address'] + ); + } + + $data['refunds'] = array(); + + foreach ($klarna_order['refunds'] as $capture) { + $max_refund_amount -= ($capture['refunded_amount'] / 100); + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['refunded_at'])), + 'amount' => $this->currency->format($capture['refunded_amount'] / 100, $order_info['currency_code'], '1.00000000', true) + ); + } + + if (!$max_capture_amount) { + $capture_action = false; + } + + if (!$max_refund_amount) { + $refund_action = false; + } + + $data['allowed_shipping_methods'] = array( + 'PickUpStore', + 'Home', + 'BoxReg', + 'BoxUnreg', + 'PickUpPoint', + 'Own' + ); + + $data['extend_authorization_action'] = $extend_authorization_action; + $data['cancel_action'] = $cancel_action; + $data['capture_action'] = $capture_action; + $data['refund_action'] = $refund_action; + $data['address_action'] = $address_action; + $data['merchant_reference_action'] = $merchant_reference_action; + $data['release_authorization_action'] = $release_authorization_action; + $data['max_capture_amount'] = $this->currency->format($max_capture_amount, $order_info['currency_code'], '1.00000000', false); + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $order_info['currency_code'], '1.00000000', false); + $data['symbol_left'] = $this->currency->getSymbolLeft($order_info['currency_code']); + $data['symbol_right'] = $this->currency->getSymbolRight($order_info['currency_code']); + + // The URL we send API requests to + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $this->response->setOutput($this->load->view('extension/payment/klarna_checkout_order_ajax', $data)); + } + + public function install() { + $this->load->model('extension/payment/klarna_checkout'); + $this->model_extension_payment_klarna_checkout->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/klarna_checkout'); + $this->model_extension_payment_klarna_checkout->uninstall(); + } + + public function transactionCommand() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + $json = array(); + + $success = $error = ''; + + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + + list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']); + + if (!$klarna_account || !$connector) { + return; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']); + + if (!$klarna_order) { + return; + } + + $old_klarna_status = $klarna_order['status']; + + if ($this->request->post['type'] == 'cancel') { + $action = $this->model_extension_payment_klarna_checkout->omCancel($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'capture' && $this->request->post['data']) { + $action = $this->model_extension_payment_klarna_checkout->omCapture($connector, $this->request->post['order_ref'], array( + 'captured_amount' => $this->request->post['data'] * 100 + )); + } elseif ($this->request->post['type'] == 'refund' && $this->request->post['data']) { + $action = $this->model_extension_payment_klarna_checkout->omRefund($connector, $this->request->post['order_ref'], array( + 'refunded_amount' => $this->request->post['data'] * 100 + )); + } elseif ($this->request->post['type'] == 'extend_authorization') { + $action = $this->model_extension_payment_klarna_checkout->omExtendAuthorizationTime($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'merchant_reference' && $this->request->post['data']) { + $data = array(); + parse_str(html_entity_decode($this->request->post['data']), $data); + + $action = $this->model_extension_payment_klarna_checkout->omUpdateMerchantReference($connector, $this->request->post['order_ref'], array( + 'merchant_reference1' => (string)$data['merchant_reference_1'] + )); + } elseif (($this->request->post['type'] == 'billing_address' || $this->request->post['type'] == 'shipping_address') && $this->request->post['data']) { + if ($this->request->post['type'] == 'billing_address') { + $data['billing_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']); + } else if ($this->request->post['type'] == 'shipping_address') { + $data['shipping_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['shipping_address']); + } + + $action = $this->model_extension_payment_klarna_checkout->omUpdateAddress($connector, $this->request->post['order_ref'], $data); + } elseif ($this->request->post['type'] == 'release_authorization') { + $action = $this->model_extension_payment_klarna_checkout->omReleaseAuthorization($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'capture_shipping_info' && isset($this->request->post['id'])) { + $data = array(); + parse_str(html_entity_decode($this->request->post['data']), $data); + + $action = $this->model_extension_payment_klarna_checkout->omShippingInfo($connector, $this->request->post['order_ref'], $this->request->post['id'], $data); + } elseif ($this->request->post['type'] == 'capture_billing_address' && isset($this->request->post['id'])) { + $data['billing_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']); + + $action = $this->model_extension_payment_klarna_checkout->omCustomerDetails($connector, $this->request->post['order_ref'], $this->request->post['id'], $data); + } elseif ($this->request->post['type'] == 'trigger_send_out' && isset($this->request->post['id'])) { + $action = $this->model_extension_payment_klarna_checkout->omTriggerSendOut($connector, $this->request->post['order_ref'], $this->request->post['id']); + } else { + $error = true; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']); + + if (!$klarna_order) { + return; + } + + $new_klarna_status = $klarna_order['status']; + + $order_status_id = ''; + if ($old_klarna_status != $new_klarna_status) { + switch ($klarna_order['status']) { + case 'AUTHORIZED': + $order_status_id = $this->config->get('klarna_checkout_order_status_authorised_id'); + + if ($klarna_order['fraud_status'] == 'PENDING') { + $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_pending_id'); + } elseif ($klarna_order['fraud_status'] == 'REJECTED') { + $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_rejected_id'); + } + break; + case 'PART_CAPTURED': + $order_status_id = $this->config->get('klarna_checkout_order_status_part_captured_id'); + break; + case 'CAPTURED': + $order_status_id = $this->config->get('klarna_checkout_order_status_captured_id'); + break; + case 'CANCELLED': + $order_status_id = $this->config->get('klarna_checkout_order_status_cancelled_id'); + break; + } + } elseif ($this->request->post['type'] == 'refund' && ($klarna_order['captured_amount'] - $klarna_order['refunded_amount'] == 0)) { + $order_status_id = $this->config->get('klarna_checkout_order_status_refund_id'); + } + + if (!$error && $action) { + $success = $this->language->get('text_success_action'); + } elseif (!$error && $action && isset($action->message)) { + $error = sprintf($this->language->get('text_error_settle'), $action->message); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + $json['order_status_id'] = $order_status_id; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function downloadSettlementFiles() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + $json = array(); + + $error = array(); + + $klarna_checkout_directory = DIR_UPLOAD . 'klarna_checkout/'; + + if (isset($this->request->post['username'])) { + $username = $this->request->post['username']; + } else { + $username = ''; + } + + if (isset($this->request->post['password'])) { + $password = html_entity_decode($this->request->post['password']); + } else { + $password = ''; + } + + if (isset($this->request->post['order_status_id'])) { + $order_status_id = $this->request->post['order_status_id']; + } else { + $order_status_id = false; + } + + if (!$username || !$password || !$order_status_id) { + $error[] = 'Please supply a username, password and order status'; + } + + if (!$error) { + // Connect to the site via FTP + $connection = ftp_connect('mft.klarna.com', '4001'); + + $files = array(); + + if ($connection) { + $login = ftp_login($connection, $username, $password); + + if ($login) { + $files = ftp_nlist($connection, '.'); + + rsort($files); + + if (!is_dir($klarna_checkout_directory)) { + mkdir($klarna_checkout_directory, 0777); + } + + // Save all files to local + foreach (array_diff($files, array('.', '..')) as $file) { + if (!ftp_get($connection, $klarna_checkout_directory . $file, $file, FTP_BINARY)) { + $error[] = 'There was a problem saving one or more files'; + } + } + } + } + } + + $orders_to_process = array(); + + $files = scandir($klarna_checkout_directory); + + if (!$error) { + // Loop local files and process + foreach (array_diff($files, array('.', '..')) as $file) { + $handle = fopen($klarna_checkout_directory . $file, 'r'); + + // Skip first 2 lines, use third as headings + fgetcsv($handle); + fgetcsv($handle); + $headings = fgetcsv($handle); + + while ($data = fgetcsv($handle)) { + $row = array_combine($headings, $data); + + if ($row['type'] == 'SALE') { + $order_id = $this->encryption->decrypt($this->config->get('config_encryption'), $row['merchant_reference1']); + + $klarna_order_info = $this->model_extension_payment_klarna_checkout->getOrder($order_id); + + $order_info = $this->model_sale_order->getOrder($order_id); + + // Check if order exists in system, if it does, pass back to process + if ($klarna_order_info && $order_info && ($order_info['payment_code'] == 'klarna_checkout') && ($order_info['order_status_id'] != $order_status_id)) { + $orders_to_process[] = $order_id; + } + } + } + + fclose($handle); + } + } + + // Delete local files + foreach (array_diff($files, array('.', '..')) as $file) { + if (!unlink($klarna_checkout_directory . $file)) { + $error[] = 'Cannot delete files'; + } + } + + if ($error) { + $orders_to_process = array(); + } + + $json['error'] = $error; + $json['orders'] = $orders_to_process; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('localisation/geo_zone'); + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_checkout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->config->get('config_secure')) { + $this->error['warning'] = $this->language->get('error_ssl'); + } + + if (empty($this->request->post['klarna_checkout_account'])) { + $this->error['account_warning'] = $this->language->get('error_account_minimum'); + } else { + $currencies = array(); + + foreach ($this->request->post['klarna_checkout_account'] as $key => $account) { + if (in_array($account['currency'], $currencies)) { + $this->error['account_warning'] = $this->language->get('error_account_currency'); + + break; + } else { + $currencies[] = $account['currency']; + } + + if (!$account['merchant_id']) { + $this->error['account'][$key]['merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$account['secret']) { + $this->error['account'][$key]['secret'] = $this->language->get('error_secret'); + } + + if (!$account['locale']) { + $this->error['account'][$key]['locale'] = $this->language->get('error_locale'); + } + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_invoice.php b/public/admin/controller/extension/payment/klarna_invoice.php new file mode 100644 index 0000000..584d9cd --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_invoice.php @@ -0,0 +1,201 @@ +<?php +class ControllerExtensionPaymentKlarnaInvoice extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/klarna_invoice'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['payment_klarna_invoice'] as $klarna_invoice) { + if ($klarna_invoice['status']) { + $status = true; + + break; + } + } + + $klarna_data = array( + 'klarna_invoice_pclasses' => $this->pclasses, + 'klarna_invoice_status' => $status + ); + + $this->model_setting_setting->editSetting('payment_klarna_invoice', array_merge($this->request->post, $klarna_data)); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + 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'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['payment_klarna_invoice'])) { + $data['payment_klarna_invoice'] = $this->request->post['payment_klarna_invoice']; + } else { + $data['payment_klarna_invoice'] = $this->config->get('payment_klarna_invoice'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $file = DIR_LOGS . 'klarna_invoice.log'; + + if (file_exists($file)) { + $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null); + } else { + $data['log'] = ''; + } + + $data['clear'] = $this->url->link('extension/payment/klarna_invoice/clear', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_invoice', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_invoice')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + private function parseResponse($node, $document) { + $child = $node; + + switch ($child->nodeName) { + case 'string': + $value = $child->nodeValue; + break; + + case 'boolean': + $value = (string)$child->nodeValue; + + if ($value == '0') { + $value = false; + } elseif ($value == '1') { + $value = true; + } else { + $value = null; + } + + break; + + case 'integer': + case 'int': + case 'i4': + case 'i8': + $value = (int)$child->nodeValue; + break; + + case 'array': + $value = array(); + + $xpath = new DOMXPath($document); + $entries = $xpath->query('.//array/data/value', $child); + + for ($i = 0; $i < $entries->length; $i++) { + $value[] = $this->parseResponse($entries->item($i)->firstChild, $document); + } + + break; + + default: + $value = null; + } + + return $value; + } + + public function clear() { + $this->load->language('extension/payment/klarna_invoice'); + + $file = DIR_LOGS . 'klarna_invoice.log'; + + $handle = fopen($file, 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/laybuy.php b/public/admin/controller/extension/payment/laybuy.php new file mode 100644 index 0000000..5c9cd86 --- /dev/null +++ b/public/admin/controller/extension/payment/laybuy.php @@ -0,0 +1,1121 @@ +<?php +class ControllerExtensionPaymentLaybuy extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + unset($this->request->post['laybuy_cron_url'], $this->request->post['laybuy_cron_time']); + + $this->model_setting_setting->editSetting('payment_laybuy', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true); + + $data['fetch'] = $this->url->link('extension/payment/laybuy/fetch', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_laybuys_membership_id'])) { + $data['payment_laybuys_membership_id'] = $this->request->post['payment_laybuys_membership_id']; + } else { + $data['payment_laybuys_membership_id'] = $this->config->get('payment_laybuys_membership_id'); + } + + if (isset($this->request->post['payment_laybuy_token'])) { + $data['payment_laybuy_token'] = $this->request->post['payment_laybuy_token']; + } elseif ($this->config->has('payment_laybuy_token')) { + $data['payment_laybuy_token'] = $this->config->get('payment_laybuy_token'); + } else { + $data['payment_laybuy_token'] = md5(time()); + } + + if (isset($this->request->post['payment_laybuy_min_deposit'])) { + $data['payment_laybuy_min_deposit'] = $this->request->post['payment_laybuy_min_deposit']; + } elseif ($this->config->get('payment_laybuy_min_deposit')) { + $data['payment_laybuy_min_deposit'] = $this->config->get('payment_laybuy_min_deposit'); + } else { + $data['payment_laybuy_min_deposit'] = '20'; + } + + if (isset($this->request->post['payment_laybuy_max_deposit'])) { + $data['payment_laybuy_max_deposit'] = $this->request->post['payment_laybuy_max_deposit']; + } elseif ($this->config->get('payment_laybuy_max_deposit')) { + $data['payment_laybuy_max_deposit'] = $this->config->get('payment_laybuy_max_deposit'); + } else { + $data['payment_laybuy_max_deposit'] = '50'; + } + + if (isset($this->request->post['payment_laybuy_max_months'])) { + $data['payment_laybuy_max_months'] = $this->request->post['payment_laybuy_max_months']; + } elseif ($this->config->get('payment_laybuy_max_months')) { + $data['payment_laybuy_max_months'] = $this->config->get('payment_laybuy_max_months'); + } else { + $data['payment_laybuy_max_months'] = '3'; + } + + if (isset($this->request->post['payment_laybuy_category'])) { + $data['payment_laybuy_category'] = $this->request->post['payment_laybuy_category']; + } elseif ($this->config->get('payment_laybuy_category')) { + $data['payment_laybuy_category'] = $this->config->get('payment_laybuy_category'); + } else { + $data['payment_laybuy_category'] = array(); + } + + $data['categories'] = array(); + + $this->load->model('catalog/category'); + + foreach ($data['payment_laybuy_category'] as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $data['categories'][] = array( + 'category_id' => $category_info['category_id'], + 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] + ); + } + } + + if (isset($this->request->post['payment_laybuy_xproducts'])) { + $data['payment_laybuy_xproducts'] = $this->request->post['payment_laybuy_xproducts']; + } else { + $data['payment_laybuy_xproducts'] = $this->config->get('payment_laybuy_xproducts'); + } + + if (isset($this->request->post['payment_laybuy_customer_group'])) { + $data['payment_laybuy_customer_group'] = $this->request->post['payment_laybuy_customer_group']; + } elseif ($this->config->get('payment_laybuy_customer_group')) { + $data['payment_laybuy_customer_group'] = $this->config->get('payment_laybuy_customer_group'); + } else { + $data['payment_laybuy_customer_group'] = array(); + } + + $data['customer_groups'] = array(); + + $this->load->model('customer/customer_group'); + + foreach ($data['payment_laybuy_customer_group'] as $customer_group_id) { + $customer_group_info = $this->model_customer_customer_group->getCustomerGroup($customer_group_id); + + if ($customer_group_info) { + $data['customer_groups'][] = array( + 'customer_group_id' => $customer_group_info['customer_group_id'], + 'name' => $customer_group_info['name'] + ); + } + } + + if (isset($this->request->post['payment_laybuy_logging'])) { + $data['payment_laybuy_logging'] = $this->request->post['payment_laybuy_logging']; + } else { + $data['payment_laybuy_logging'] = $this->config->get('payment_laybuy_logging'); + } + + if (isset($this->request->post['payment_laybuy_total'])) { + $data['payment_laybuy_total'] = $this->request->post['payment_laybuy_total']; + } else { + $data['payment_laybuy_total'] = $this->config->get('payment_laybuy_total'); + } + + if (isset($this->request->post['payment_laybuy_order_status_id_pending'])) { + $data['payment_laybuy_order_status_id_pending'] = $this->request->post['payment_laybuy_order_status_id_pending']; + } elseif ($this->config->get('payment_laybuy_order_status_id_pending')) { + $data['payment_laybuy_order_status_id_pending'] = $this->config->get('payment_laybuy_order_status_id_pending'); + } else { + $data['payment_laybuy_order_status_id_pending'] = '1'; + } + + if (isset($this->request->post['payment_laybuy_order_status_id_canceled'])) { + $data['payment_laybuy_order_status_id_canceled'] = $this->request->post['payment_laybuy_order_status_id_canceled']; + } elseif ($this->config->get('payment_laybuy_order_status_id_canceled')) { + $data['payment_laybuy_order_status_id_canceled'] = $this->config->get('payment_laybuy_order_status_id_canceled'); + } else { + $data['payment_laybuy_order_status_id_canceled'] = '7'; + } + + if (isset($this->request->post['payment_laybuy_order_status_id_processing'])) { + $data['payment_laybuy_order_status_id_processing'] = $this->request->post['payment_laybuy_order_status_id_processing']; + } elseif ($this->config->get('payment_laybuy_order_status_id_processing')) { + $data['payment_laybuy_order_status_id_processing'] = $this->config->get('payment_laybuy_order_status_id_processing'); + } else { + $data['payment_laybuy_order_status_id_processing'] = '2'; + } + + if (isset($this->request->post['payment_laybuy_gateway_url'])) { + $data['payment_laybuy_gateway_url'] = $this->request->post['payment_laybuy_gateway_url']; + } elseif ($this->config->get('payment_laybuy_gateway_url')) { + $data['payment_laybuy_gateway_url'] = $this->config->get('payment_laybuy_gateway_url'); + } else { + $data['payment_laybuy_gateway_url'] = 'http://lay-buys.com/gateway/'; + } + + if (isset($this->request->post['payment_laybuy_api_url'])) { + $data['payment_laybuy_api_url'] = $this->request->post['payment_laybuy_api_url']; + } elseif ($this->config->get('payment_laybuy_api_url')) { + $data['payment_laybuy_api_url'] = $this->config->get('payment_laybuy_api_url'); + } else { + $data['payment_laybuy_api_url'] = 'https://lay-buys.com/report/'; + } + + if (isset($this->request->post['payment_laybuy_geo_zone_id'])) { + $data['payment_laybuy_geo_zone_id'] = $this->request->post['payment_laybuy_geo_zone_id']; + } else { + $data['payment_laybuy_geo_zone_id'] = $this->config->get('payment_laybuy_geo_zone_id'); + } + + if (isset($this->request->post['payment_laybuy_status'])) { + $data['payment_laybuy_status'] = $this->request->post['payment_laybuy_status']; + } else { + $data['payment_laybuy_status'] = $this->config->get('payment_laybuy_status'); + } + + if (isset($this->request->post['payment_laybuy_sort_order'])) { + $data['payment_laybuy_sort_order'] = $this->request->post['payment_laybuy_sort_order']; + } else { + $data['payment_laybuy_sort_order'] = $this->config->get('payment_laybuy_sort_order'); + } + + $data['laybuy_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/cron&token=' . $data['payment_laybuy_token']; + + if ($this->config->get('laybuy_cron_time')) { + $data['laybuy_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('laybuy_cron_time'))); + } else { + $data['laybuy_cron_time'] = $this->language->get('text_no_cron_time'); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['laybuys_membership_id'])) { + $data['error_laybuys_membership_id'] = $this->error['laybuys_membership_id']; + } else { + $data['error_laybuys_membership_id'] = ''; + } + + if (isset($this->error['laybuy_token'])) { + $data['error_laybuy_token'] = $this->error['laybuy_token']; + } else { + $data['error_laybuy_token'] = ''; + } + + if (isset($this->error['laybuy_min_deposit'])) { + $data['error_laybuy_min_deposit'] = $this->error['laybuy_min_deposit']; + } else { + $data['error_laybuy_min_deposit'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + /* Reports tab */ + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_dp_percent'])) { + $filter_dp_percent = $this->request->get['filter_dp_percent']; + } else { + $filter_dp_percent = ''; + } + + if (isset($this->request->get['filter_months'])) { + $filter_months = $this->request->get['filter_months']; + } else { + $filter_months = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'lt.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; + } + + $data['reports'] = array(); + + $filter_data = array( + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_dp_percent' => $filter_dp_percent, + 'filter_months' => $filter_months, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $report_total = $this->model_extension_payment_laybuy->getTotalTransactions($filter_data); + + $results = $this->model_extension_payment_laybuy->getTransactions($filter_data); + + foreach ($results as $result) { + $customer_url = false; + + $customer_id = $this->model_extension_payment_laybuy->getCustomerIdByOrderId($result['order_id']); + + if ($customer_id) { + $customer_url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$customer_id, true); + } + + $data['reports'][] = array( + 'id' => $result['laybuy_transaction_id'], + 'order_id' => $result['order_id'], + 'order_url' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$result['order_id'], true), + 'customer_name' => $result['firstname'] . ' ' . $result['lastname'], + 'customer_url' => $customer_url, + 'amount' => $this->currency->format($result['amount'], $result['currency']), + 'dp_percent' => $result['downpayment'], + 'months' => $result['months'], + 'dp_amount' => $this->currency->format($result['downpayment_amount'], $result['currency']), + 'first_payment' => date($this->language->get('date_format_short'), strtotime($result['first_payment_due'])), + 'last_payment' => date($this->language->get('date_format_short'), strtotime($result['last_payment_due'])), + 'status' => $this->model_extension_payment_laybuy->getStatusLabel($result['status']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'view' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . (int)$result['laybuy_transaction_id'], true) + ); + } + + 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=' . urlencode(html_entity_decode($this->request->get['filter_order_id'], ENT_QUOTES, 'UTF-8')); + } + + 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_dp_percent'])) { + $url .= '&filter_dp_percent=' . urlencode(html_entity_decode($this->request->get['filter_dp_percent'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_months'])) { + $url .= '&filter_months=' . $this->request->get['filter_months']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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_id'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.order_id' . $url . '#reportstab', true); + $data['sort_customer'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url . '#reportstab', true); + $data['sort_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.amount' . $url . '#reportstab', true); + $data['sort_dp_percent'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment' . $url . '#reportstab', true); + $data['sort_months'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.months' . $url . '#reportstab', true); + $data['sort_dp_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment_amount' . $url . '#reportstab', true); + $data['sort_first_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.first_payment_due' . $url . '#reportstab', true); + $data['sort_last_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.last_payment_due' . $url . '#reportstab', true); + $data['sort_status'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.status' . $url . '#reportstab', true); + $data['sort_date_added'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.date_added' . $url . '#reportstab', true); + + $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=' . $this->request->get['filter_customer']; + } + + if (isset($this->request->get['filter_dp_percent'])) { + $url .= '&filter_dp_percent=' . $this->request->get['filter_dp_percent']; + } + + if (isset($this->request->get['filter_months'])) { + $url .= '&filter_months=' . $this->request->get['filter_months']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $report_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}#reportstab', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($report_total - $this->config->get('config_limit_admin'))) ? $report_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $report_total, ceil($report_total / $this->config->get('config_limit_admin'))); + + $data['filter_order_id'] = $filter_order_id; + $data['filter_customer'] = $filter_customer; + $data['filter_dp_percent'] = $filter_dp_percent; + $data['filter_months'] = $filter_months; + $data['filter_status'] = $filter_status; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['transaction_statuses'] = $this->model_extension_payment_laybuy->getTransactionStatuses(); + /* End of Reports Tab */ + + $data['user_token'] = $this->session->data['user_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'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/laybuy', $data)); + } + + public function fetch() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Fetching transactions'); + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $fetched = 0; + + $paypal_profile_id_array = $this->model_extension_payment_laybuy->getPayPalProfileIds(); + + if ($paypal_profile_id_array) { + $paypal_profile_ids = ''; + + foreach ($paypal_profile_id_array as $profile_id) { + $paypal_profile_ids .= $profile_id['paypal_profile_id'] . ','; + } + + $paypal_profile_ids = rtrim($paypal_profile_ids, ','); + + $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'profileIds=' . $paypal_profile_ids; + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $this->model_extension_payment_laybuy->log('API URL: ' . $this->config->get('payment_laybuy_api_url')); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->config->get('payment_laybuy_api_url')); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + $results = json_decode($result, true); + + $this->model_extension_payment_laybuy->log('Response: ' . print_r($results, true)); + + if ($results) { + foreach ($results as $laybuy_ref_id => $reports) { + $status = $reports['status']; + + $report = $reports['report']; + + $transaction = array(); + + $transaction = $this->model_extension_payment_laybuy->getTransactionByLayBuyRefId($laybuy_ref_id); + + $order_id = $transaction['order_id']; + + $paypal_profile_id = $transaction['paypal_profile_id']; + + $months = $transaction['months']; + + $report_content = array(); + + $pending_flag = false; + + $next_payment_status = $this->language->get('text_status_1'); + + foreach ($report as $month => $payment) { + $payment['paymentDate'] = date('Y-m-d h:i:s', strtotime(str_replace('/', '-', $payment['paymentDate']))); + $date = date($this->language->get('date_format_short'), strtotime($payment['paymentDate'])); + $next_payment_date = $payment['paymentDate']; + + if ($payment['type'] == 'd') { + $report_content[] = array( + 'instalment' => 0, + 'amount' => $this->currency->format($payment['amount'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => $payment['txnID'], + 'status' => $payment['paymentStatus'] + ); + } elseif ($payment['type'] == 'p') { + $pending_flag = true; + + $report_content[] = array( + 'instalment' => $month, + 'amount' => $this->currency->format($payment['amount'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => $payment['txnID'], + 'status' => $payment['paymentStatus'] + ); + + $next_payment_status = $payment['paymentStatus']; + } + } + + if ($pending_flag) { + $start_index = $month + 1; + } else { + $start_index = $month + 2; + } + + if ($month < $months) { + for ($month = 1; $month <= $months; $month++) { + $next_payment_date = date("Y-m-d h:i:s", strtotime($next_payment_date . " +1 month")); + $date = date($this->language->get('date_format_short'), strtotime($next_payment_date)); + + $report_content[] = array( + 'instalment' => $month, + 'amount' => $this->currency->format($transaction['payment_amounts'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => '', + 'status' => $next_payment_status + ); + } + } + + $report_content = json_encode($report_content); + + switch ($status) { + case -1: // Cancel + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' canceled'); + $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_canceled'), $this->language->get('text_comment')); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '7', $report_content, $start_index); + $fetched++; + break; + case 0: // Pending + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' still pending'); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], $transaction['status'], $report_content, $start_index); + $fetched++; + break; + case 1: // Paid + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' paid'); + $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_processing'), $this->language->get('text_comment')); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '5', $report_content, $start_index); + $fetched++; + break; + } + } + } + + if ($fetched) { + $this->session->data['success'] = sprintf($this->language->get('text_fetched_some'), $fetched); + } else { + $this->session->data['success'] = $this->language->get('text_fetched_none'); + } + + $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->model_extension_payment_laybuy->log('No PayPal Profile IDs to update'); + + $this->session->data['success'] = $this->language->get('text_fetched_none'); + + $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->uninstall(); + } + } + + public function transaction($order_page = false) { + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + if (isset($this->request->get['id'])) { + $id = (int)$this->request->get['id']; + } else { + $id = 0; + } + + $data['id'] = $id; + + if (!$order_page) { + $this->document->setTitle($this->language->get('heading_transaction_title')); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_transaction_title'), + 'href' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true) + ); + + $data['heading_title'] = $this->language->get('heading_transaction_title'); + + $data['button_cancel'] = $this->language->get('button_cancel'); + + $data['cancel'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true); + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + if ($transaction_info) { + $data['initial_payments'] = $this->model_extension_payment_laybuy->getInitialPayments(); + + $data['months'] = $this->model_extension_payment_laybuy->getMonths(); + + $data['currency_symbol_left'] = $this->currency->getSymbolLeft($transaction_info['currency']); + + $data['currency_symbol_right'] = $this->currency->getSymbolRight($transaction_info['currency']); + + $data['store_url'] = HTTPS_CATALOG; + + $data['api_key'] = $this->getApiKey(); + + $this->load->model('sale/order'); + + $order = $this->model_sale_order->getOrder($transaction_info['order_id']); + + $data['order_info'] = array( + 'currency_value' => $order['currency_value'] + ); + + $data['total'] = $this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']); + + $data['transaction'] = array( + 'paypal_profile_id' => $transaction_info['paypal_profile_id'], + 'laybuy_ref_no' => $transaction_info['laybuy_ref_no'], + 'order_id' => $transaction_info['order_id'], + 'firstname' => $transaction_info['firstname'], + 'lastname' => $transaction_info['lastname'], + 'email' => $transaction_info['email'], + 'address' => $transaction_info['address'], + 'suburb' => $transaction_info['suburb'], + 'state' => $transaction_info['state'], + 'country' => $transaction_info['country'], + 'postcode' => $transaction_info['postcode'], + 'status_id' => $transaction_info['status'], + 'status' => $this->model_extension_payment_laybuy->getStatusLabel($transaction_info['status']), + 'amount' => $this->currency->format($transaction_info['amount'], $transaction_info['currency']), + 'remaining' => $this->currency->format($this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']), $transaction_info['currency']), + 'downpayment' => $transaction_info['downpayment'], + 'months' => $transaction_info['months'], + 'downpayment_amount' => $this->currency->format($transaction_info['downpayment_amount'], $transaction_info['currency']), + 'payment_amounts' => $this->currency->format($transaction_info['payment_amounts'], $transaction_info['currency']), + 'first_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['first_payment_due'])), + 'last_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['last_payment_due'])), + 'report' => json_decode($transaction_info['report'], true) + ); + } else { + $data['transaction'] = array(); + + $data['text_not_found'] = $this->language->get('text_not_found'); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->session->data['error_warning'])) { + $data['error_warning'] = $this->session->data['error_warning']; + + unset($this->session->data['error_warning']); + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + if ($order_page) { + return $data; + } + + $this->response->setOutput($this->load->view('extension/payment/laybuy_transaction', $data)); + } + + public function cancel() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Canceling transaction'); + + if ($this->request->get['source'] == 'order') { + $this->model_extension_payment_laybuy->log('Called from order page'); + } else { + $this->model_extension_payment_laybuy->log('Called from extension page'); + } + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $id = (int)$this->request->get['id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + $cancel = false; + + if (!$transaction_info['paypal_profile_id']) { + $this->model_extension_payment_laybuy->log('Transaction has no paypal_profile_id'); + + $cancel = true; + } + + if (!$cancel) { + $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'paypal_profile_id=' . $transaction_info['paypal_profile_id']; + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $ch = curl_init(); + $url = 'https://lay-buys.com/vtmob/deal5cancel.php'; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + $this->model_extension_payment_laybuy->log('Response: ' . $result); + + if ($result == 'success') { + $this->model_extension_payment_laybuy->log('Success'); + + $cancel = true; + } else { + $this->model_extension_payment_laybuy->log('Failure'); + } + } + + if ($cancel) { + $this->model_extension_payment_laybuy->log('Transaction canceled'); + + $report_content = json_decode($transaction_info['report'], true); + + foreach ($report_content as &$array) { + $array['status'] = str_replace('Pending', 'Canceled', $array['status']); + } + + $report_content = json_encode($report_content); + + $this->model_extension_payment_laybuy->updateTransaction($transaction_info['laybuy_transaction_id'], '7', $report_content, $transaction_info['transaction']); + + $json['success'] = $this->language->get('text_cancel_success'); + + $json['order_id'] = $transaction_info['order_id']; + + $json['order_status_id'] = $this->config->get('payment_laybuy_order_status_id_canceled'); + + $json['comment'] = sprintf($this->language->get('text_comment_canceled'), $transaction_info['paypal_profile_id']); + } else { + $json['error'] = $this->language->get('text_cancel_failure'); + } + + if ($this->request->get['source'] == 'order') { + $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true); + } else { + $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true); + } + + $this->response->setOutput(json_encode($json)); + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function revise() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Revising transaction'); + + if ($this->request->get['source'] == 'order') { + $this->model_extension_payment_laybuy->log('Called from order page'); + } else { + $this->model_extension_payment_laybuy->log('Called from extension page'); + } + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $payment_type = $this->request->post['payment_type']; + + $amount = $this->request->post['amount']; + + $initial = $this->request->post['INIT']; + + $months = $this->request->post['MONTHS']; + + $id = $this->request->get['id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + $original = $new = $transaction_info; + + $original['transaction_id'] = $new['transaction_id'] = $transaction_info['laybuy_transaction_id']; + + $original['payment_type'] = $new['payment_type'] = $payment_type; + + $original['type'] = 'Original'; + + $new['type'] = 'New'; + $new['status'] = '50'; + $new['amount'] = $amount; + $new['downpayment'] = $initial; + $new['months'] = $months; + + $collection = $this->model_extension_payment_laybuy->getRevisedTransactions($id); + + $this->model_extension_payment_laybuy->log('Collection: ' . print_r($collection, true)); + + if (count($collection) == 2) { + $this->model_extension_payment_laybuy->log('Collection == 2'); + + foreach ($collection as $request) { + $this->model_extension_payment_laybuy->log('request: ' . print_r($request, true)); + + if ($request['type'] == 'Original') { + $this->model_extension_payment_laybuy->log('Original: ' . print_r($original, true)); + + $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $original); + } elseif ($request['type'] == 'New') { + $this->model_extension_payment_laybuy->log('New: ' . print_r($new, true)); + + $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $new); + + $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($id); + } + } + } else { + $this->model_extension_payment_laybuy->log('Collection != 2'); + + $this->model_extension_payment_laybuy->addRevisedTransaction($original); + + $laybuy_revise_request_id = $this->model_extension_payment_laybuy->addRevisedTransaction($new); + + $this->model_extension_payment_laybuy->log('$laybuy_revise_request_id: ' . $laybuy_revise_request_id); + + $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($laybuy_revise_request_id); + } + + $this->model_extension_payment_laybuy->log('Revised transaction: ' . print_r($revised_transaction, true)); + + if ($revised_transaction['payment_type'] == '1') { + $pp = '1'; + $pplan = '1'; + } else { + $pp = '0'; + $pplan = '0'; + } + + $data = array(); + + $data['mid'] = $this->config->get('payment_laybuys_membership_id'); + $data['eml'] = $revised_transaction['email']; + $data['prc'] = $revised_transaction['amount']; + $data['curr'] = $revised_transaction['currency']; + $data['pp'] = $pp; + $data['pplan'] = $pplan; + $data['init'] = $initial; + $data['mnth'] = $months; + $data['convrate'] = '1'; + $data['id'] = $revised_transaction['laybuy_revise_request_id'] . '-' . $revised_transaction['order_id'] . ':' . md5($this->config->get('payment_laybuy_token')); + $data['RETURNURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCallback'; + $data['CANCELURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCancel'; + + $data_string = ''; + + foreach ($data as $param => $value) { + $data_string .= $param . '=' . $value . '&'; + } + + $data_string = rtrim($data_string, '&'); + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $ch = curl_init(); + $url = 'https://lay-buys.com/vtmob/deal5.php'; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + if ($result == 'success') { + $this->model_extension_payment_laybuy->log('Success'); + + $this->model_extension_payment_laybuy->updateTransactionStatus($id, '50'); + + $json['success'] = $this->language->get('text_revise_success'); + } else { + $this->model_extension_payment_laybuy->log('Failure'); + + $this->model_extension_payment_laybuy->log('Response: ' . print_r($result, true)); + + $json['error'] = $this->language->get('text_revise_failure'); + } + + if ($this->request->get['source'] == 'order') { + $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true); + } else { + $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true); + } + + $this->response->setOutput(json_encode($json)); + } else { + $this->model_extension_payment_laybuy->log('No $_POST data'); + } + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_customer_group'])) { + $this->load->model('customer/customer_group'); + + $results = $this->model_customer_customer_group->getCustomerGroups(); + + foreach ($results as $result) { + $json[] = array( + 'customer_group_id' => $result['customer_group_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + if ($this->config->get('payment_laybuy_status')) { + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + $order_id = $this->request->get['order_id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransactionByOrderId($order_id); + + $laybuy_transaction_id = $transaction_info['laybuy_transaction_id']; + + $this->request->get['id'] = $laybuy_transaction_id; + + $data = $this->transaction(true); + + $data['store_url'] = HTTPS_CATALOG; + + $data['api_key'] = $this->getApiKey(); + + return $this->load->view('extension/payment/laybuy_order', $data); + } + } + + private function getApiKey() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Getting API key'); + + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info) { + $this->model_extension_payment_laybuy->log('API key: ' . $api_info['key']); + + return $api_info['key']; + } else { + $this->model_extension_payment_laybuy->log('No API info'); + + return; + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_laybuys_membership_id']) { + $this->error['laybuys_membership_id'] = $this->language->get('error_membership_id'); + } + + if (!$this->request->post['payment_laybuy_token']) { + $this->error['laybuy_token'] = $this->language->get('error_token'); + } + + if ($this->request->post['payment_laybuy_min_deposit'] > $this->request->post['payment_laybuy_max_deposit']) { + $this->error['laybuy_min_deposit'] = $this->language->get('error_min_deposit'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/liqpay.php b/public/admin/controller/extension/payment/liqpay.php new file mode 100644 index 0000000..7f0841c --- /dev/null +++ b/public/admin/controller/extension/payment/liqpay.php @@ -0,0 +1,143 @@ +<?php +class ControllerExtensionPaymentLiqPay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/liqpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_liqpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + if (isset($this->error['type'])) { + $data['error_type'] = $this->error['type']; + } else { + $data['error_type'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/liqpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/liqpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_liqpay_merchant'])) { + $data['payment_liqpay_merchant'] = $this->request->post['payment_liqpay_merchant']; + } else { + $data['payment_liqpay_merchant'] = $this->config->get('payment_liqpay_merchant'); + } + + if (isset($this->request->post['payment_liqpay_signature'])) { + $data['payment_liqpay_signature'] = $this->request->post['payment_liqpay_signature']; + } else { + $data['payment_liqpay_signature'] = $this->config->get('payment_liqpay_signature'); + } + + if (isset($this->request->post['payment_liqpay_type'])) { + $data['payment_liqpay_type'] = $this->request->post['payment_liqpay_type']; + } else { + $data['payment_liqpay_type'] = $this->config->get('payment_liqpay_type'); + } + + if (isset($this->request->post['payment_liqpay_total'])) { + $data['payment_liqpay_total'] = $this->request->post['payment_liqpay_total']; + } else { + $data['payment_liqpay_total'] = $this->config->get('payment_liqpay_total'); + } + + if (isset($this->request->post['payment_liqpay_order_status_id'])) { + $data['payment_liqpay_order_status_id'] = $this->request->post['payment_liqpay_order_status_id']; + } else { + $data['payment_liqpay_order_status_id'] = $this->config->get('payment_liqpay_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_liqpay_geo_zone_id'])) { + $data['payment_liqpay_geo_zone_id'] = $this->request->post['payment_liqpay_geo_zone_id']; + } else { + $data['payment_liqpay_geo_zone_id'] = $this->config->get('payment_liqpay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_liqpay_status'])) { + $data['payment_liqpay_status'] = $this->request->post['payment_liqpay_status']; + } else { + $data['payment_liqpay_status'] = $this->config->get('payment_liqpay_status'); + } + + if (isset($this->request->post['payment_liqpay_sort_order'])) { + $data['payment_liqpay_sort_order'] = $this->request->post['payment_liqpay_sort_order']; + } else { + $data['payment_liqpay_sort_order'] = $this->config->get('payment_liqpay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/liqpay', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/liqpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_liqpay_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_liqpay_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/nochex.php b/public/admin/controller/extension/payment/nochex.php new file mode 100644 index 0000000..08e0413 --- /dev/null +++ b/public/admin/controller/extension/payment/nochex.php @@ -0,0 +1,149 @@ +<?php +class ControllerExtensionPaymentNOCHEX extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/nochex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_nochex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/nochex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/nochex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_nochex_email'])) { + $data['payment_nochex_email'] = $this->request->post['payment_nochex_email']; + } else { + $data['payment_nochex_email'] = $this->config->get('payment_nochex_email'); + } + + if (isset($this->request->post['payment_nochex_account'])) { + $data['payment_nochex_account'] = $this->request->post['payment_nochex_account']; + } else { + $data['payment_nochex_account'] = $this->config->get('payment_nochex_account'); + } + + if (isset($this->request->post['payment_nochex_merchant'])) { + $data['payment_nochex_merchant'] = $this->request->post['payment_nochex_merchant']; + } else { + $data['payment_nochex_merchant'] = $this->config->get('payment_nochex_merchant'); + } + + if (isset($this->request->post['payment_nochex_template'])) { + $data['payment_nochex_template'] = $this->request->post['payment_nochex_template']; + } else { + $data['payment_nochex_template'] = $this->config->get('payment_nochex_template'); + } + + if (isset($this->request->post['payment_nochex_test'])) { + $data['payment_nochex_test'] = $this->request->post['payment_nochex_test']; + } else { + $data['payment_nochex_test'] = $this->config->get('payment_nochex_test'); + } + + if (isset($this->request->post['payment_nochex_total'])) { + $data['payment_nochex_total'] = $this->request->post['payment_nochex_total']; + } else { + $data['payment_nochex_total'] = $this->config->get('payment_nochex_total'); + } + + if (isset($this->request->post['payment_nochex_order_status_id'])) { + $data['payment_nochex_order_status_id'] = $this->request->post['payment_nochex_order_status_id']; + } else { + $data['payment_nochex_order_status_id'] = $this->config->get('payment_nochex_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_nochex_geo_zone_id'])) { + $data['payment_nochex_geo_zone_id'] = $this->request->post['payment_nochex_geo_zone_id']; + } else { + $data['payment_nochex_geo_zone_id'] = $this->config->get('payment_nochex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_nochex_status'])) { + $data['payment_nochex_status'] = $this->request->post['payment_nochex_status']; + } else { + $data['payment_nochex_status'] = $this->config->get('payment_nochex_status'); + } + + if (isset($this->request->post['payment_nochex_sort_order'])) { + $data['payment_nochex_sort_order'] = $this->request->post['payment_nochex_sort_order']; + } else { + $data['payment_nochex_sort_order'] = $this->config->get('payment_nochex_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/nochex', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/nochex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_nochex_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + if (!$this->request->post['payment_nochex_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/paymate.php b/public/admin/controller/extension/payment/paymate.php new file mode 100644 index 0000000..4552e76 --- /dev/null +++ b/public/admin/controller/extension/payment/paymate.php @@ -0,0 +1,139 @@ +<?php +class ControllerExtensionPaymentPayMate extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/paymate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_paymate', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/paymate', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/paymate', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_paymate_username'])) { + $data['payment_paymate_username'] = $this->request->post['payment_paymate_username']; + } else { + $data['payment_paymate_username'] = $this->config->get('payment_paymate_username'); + } + + if (isset($this->request->post['payment_paymate_password'])) { + $data['payment_paymate_username'] = $this->request->post['payment_paymate_password']; + } elseif ($this->config->get('payment_paymate_password')) { + $data['payment_paymate_password'] = $this->config->get('payment_paymate_password'); + } else { + $data['payment_paymate_password'] = token(32); + } + + if (isset($this->request->post['payment_paymate_test'])) { + $data['payment_paymate_test'] = $this->request->post['payment_paymate_test']; + } else { + $data['payment_paymate_test'] = $this->config->get('payment_paymate_test'); + } + + if (isset($this->request->post['payment_paymate_total'])) { + $data['payment_paymate_total'] = $this->request->post['payment_paymate_total']; + } else { + $data['payment_paymate_total'] = $this->config->get('payment_paymate_total'); + } + + if (isset($this->request->post['payment_paymate_order_status_id'])) { + $data['payment_paymate_order_status_id'] = $this->request->post['payment_paymate_order_status_id']; + } else { + $data['payment_paymate_order_status_id'] = $this->config->get('payment_paymate_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_paymate_geo_zone_id'])) { + $data['payment_paymate_geo_zone_id'] = $this->request->post['payment_paymate_geo_zone_id']; + } else { + $data['payment_paymate_geo_zone_id'] = $this->config->get('payment_paymate_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_paymate_status'])) { + $data['payment_paymate_status'] = $this->request->post['payment_paymate_status']; + } else { + $data['payment_paymate_status'] = $this->config->get('payment_paymate_status'); + } + + if (isset($this->request->post['payment_paymate_sort_order'])) { + $data['payment_paymate_sort_order'] = $this->request->post['payment_paymate_sort_order']; + } else { + $data['payment_paymate_sort_order'] = $this->config->get('payment_paymate_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/paymate', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/paymate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_paymate_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_paymate_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/paypoint.php b/public/admin/controller/extension/payment/paypoint.php new file mode 100644 index 0000000..c4948a2 --- /dev/null +++ b/public/admin/controller/extension/payment/paypoint.php @@ -0,0 +1,127 @@ +<?php +class ControllerExtensionPaymentPayPoint extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/paypoint'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_paypoint', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/paypoint', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/paypoint', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_paypoint_merchant'])) { + $data['payment_paypoint_merchant'] = $this->request->post['payment_paypoint_merchant']; + } else { + $data['payment_paypoint_merchant'] = $this->config->get('payment_paypoint_merchant'); + } + + if (isset($this->request->post['payment_paypoint_password'])) { + $data['payment_paypoint_password'] = $this->request->post['payment_paypoint_password']; + } else { + $data['payment_paypoint_password'] = $this->config->get('payment_paypoint_password'); + } + + if (isset($this->request->post['payment_paypoint_test'])) { + $data['payment_paypoint_test'] = $this->request->post['payment_paypoint_test']; + } else { + $data['payment_paypoint_test'] = $this->config->get('payment_paypoint_test'); + } + + if (isset($this->request->post['payment_paypoint_total'])) { + $data['payment_paypoint_total'] = $this->request->post['payment_paypoint_total']; + } else { + $data['payment_paypoint_total'] = $this->config->get('payment_paypoint_total'); + } + + if (isset($this->request->post['payment_paypoint_order_status_id'])) { + $data['payment_paypoint_order_status_id'] = $this->request->post['payment_paypoint_order_status_id']; + } else { + $data['payment_paypoint_order_status_id'] = $this->config->get('payment_paypoint_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['paypoint_geo_zone_id'])) { + $data['paypoint_geo_zone_id'] = $this->request->post['paypoint_geo_zone_id']; + } else { + $data['paypoint_geo_zone_id'] = $this->config->get('paypoint_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['paypoint_status'])) { + $data['paypoint_status'] = $this->request->post['paypoint_status']; + } else { + $data['paypoint_status'] = $this->config->get('paypoint_status'); + } + + if (isset($this->request->post['paypoint_sort_order'])) { + $data['paypoint_sort_order'] = $this->request->post['paypoint_sort_order']; + } else { + $data['paypoint_sort_order'] = $this->config->get('paypoint_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/paypoint', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/paypoint')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_paypoint_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/payza.php b/public/admin/controller/extension/payment/payza.php new file mode 100644 index 0000000..bb250dc --- /dev/null +++ b/public/admin/controller/extension/payment/payza.php @@ -0,0 +1,133 @@ +<?php +class ControllerExtensionPaymentPayza extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/payza'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_payza', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['security'])) { + $data['error_security'] = $this->error['security']; + } else { + $data['error_security'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/payza', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/payza', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_payza_merchant'])) { + $data['payment_payza_merchant'] = $this->request->post['payment_payza_merchant']; + } else { + $data['payment_payza_merchant'] = $this->config->get('payment_payza_merchant'); + } + + if (isset($this->request->post['payment_payza_security'])) { + $data['payment_payza_security'] = $this->request->post['payment_payza_security']; + } else { + $data['payment_payza_security'] = $this->config->get('payment_payza_security'); + } + + $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/payza/callback'; + + if (isset($this->request->post['payment_payza_total'])) { + $data['payment_payza_total'] = $this->request->post['payment_payza_total']; + } else { + $data['payment_payza_total'] = $this->config->get('payment_payza_total'); + } + + if (isset($this->request->post['payment_payza_order_status_id'])) { + $data['payment_payza_order_status_id'] = $this->request->post['payment_payza_order_status_id']; + } else { + $data['payment_payza_order_status_id'] = $this->config->get('payment_payza_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_payza_geo_zone_id'])) { + $data['payment_payza_geo_zone_id'] = $this->request->post['payment_payza_geo_zone_id']; + } else { + $data['payment_payza_geo_zone_id'] = $this->config->get('payment_payza_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_payza_status'])) { + $data['payment_payza_status'] = $this->request->post['payment_payza_status']; + } else { + $data['payment_payza_status'] = $this->config->get('payment_payza_status'); + } + + if (isset($this->request->post['payment_payza_sort_order'])) { + $data['payment_payza_sort_order'] = $this->request->post['payment_payza_sort_order']; + } else { + $data['payment_payza_sort_order'] = $this->config->get('payment_payza_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/payza', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/payza')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_payza_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_payza_security']) { + $this->error['security'] = $this->language->get('error_security'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/perpetual_payments.php b/public/admin/controller/extension/payment/perpetual_payments.php new file mode 100644 index 0000000..f363b5f --- /dev/null +++ b/public/admin/controller/extension/payment/perpetual_payments.php @@ -0,0 +1,137 @@ +<?php +class ControllerExtensionPaymentPerpetualPayments extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/perpetual_payments'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_perpetual_payments', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['auth_id'])) { + $data['error_auth_id'] = $this->error['auth_id']; + } else { + $data['error_auth_id'] = ''; + } + + if (isset($this->error['auth_pass'])) { + $data['error_auth_pass'] = $this->error['auth_pass']; + } else { + $data['error_auth_pass'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/perpetual_payments', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/perpetual_payments', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_perpetual_payments_auth_id'])) { + $data['payment_perpetual_payments_auth_id'] = $this->request->post['payment_perpetual_payments_auth_id']; + } else { + $data['payment_perpetual_payments_auth_id'] = $this->config->get('payment_perpetual_payments_auth_id'); + } + + if (isset($this->request->post['payment_perpetual_payments_auth_pass'])) { + $data['payment_perpetual_payments_auth_pass'] = $this->request->post['payment_perpetual_payments_auth_pass']; + } else { + $data['payment_perpetual_payments_auth_pass'] = $this->config->get('payment_perpetual_payments_auth_pass'); + } + + if (isset($this->request->post['payment_perpetual_payments_test'])) { + $data['payment_perpetual_payments_test'] = $this->request->post['payment_perpetual_payments_test']; + } else { + $data['payment_perpetual_payments_test'] = $this->config->get('payment_perpetual_payments_test'); + } + + if (isset($this->request->post['payment_perpetual_payments_total'])) { + $data['payment_perpetual_payments_total'] = $this->request->post['payment_perpetual_payments_total']; + } else { + $data['payment_perpetual_payments_total'] = $this->config->get('payment_perpetual_payments_total'); + } + + if (isset($this->request->post['payment_perpetual_payments_order_status_id'])) { + $data['payment_perpetual_payments_order_status_id'] = $this->request->post['payment_perpetual_payments_order_status_id']; + } else { + $data['payment_perpetual_payments_order_status_id'] = $this->config->get('payment_perpetual_payments_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_perpetual_payments_geo_zone_id'])) { + $data['payment_perpetual_payments_geo_zone_id'] = $this->request->post['payment_perpetual_payments_geo_zone_id']; + } else { + $data['payment_perpetual_payments_geo_zone_id'] = $this->config->get('payment_perpetual_payments_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_perpetual_payments_status'])) { + $data['payment_perpetual_payments_status'] = $this->request->post['payment_perpetual_payments_status']; + } else { + $data['payment_perpetual_payments_status'] = $this->config->get('payment_perpetual_payments_status'); + } + + if (isset($this->request->post['payment_perpetual_payments_sort_order'])) { + $data['payment_perpetual_payments_sort_order'] = $this->request->post['payment_perpetual_payments_sort_order']; + } else { + $data['payment_perpetual_payments_sort_order'] = $this->config->get('payment_perpetual_payments_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/perpetual_payments', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/perpetual_payments')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_perpetual_payments_auth_id']) { + $this->error['auth_id'] = $this->language->get('error_auth_id'); + } + + if (!$this->request->post['payment_perpetual_payments_auth_pass']) { + $this->error['auth_pass'] = $this->language->get('error_auth_pass'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pilibaba.php b/public/admin/controller/extension/payment/pilibaba.php new file mode 100644 index 0000000..5f78593 --- /dev/null +++ b/public/admin/controller/extension/payment/pilibaba.php @@ -0,0 +1,343 @@ +<?php +class ControllerExtensionPaymentPilibaba extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/pilibaba'); + + $this->load->language('extension/payment/pilibaba'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pilibaba', $this->request->post); + + if ($this->request->post['payment_pilibaba_status']) { + $this->model_extension_payment_pilibaba->enablePiliExpress(); + } else { + $this->model_extension_payment_pilibaba->disablePiliExpress(); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pilibaba_merchant_number'])) { + $data['payment_pilibaba_merchant_number'] = $this->request->post['payment_pilibaba_merchant_number']; + } else { + $data['payment_pilibaba_merchant_number'] = $this->config->get('payment_pilibaba_merchant_number'); + } + + if (isset($this->request->post['payment_pilibaba_secret_key'])) { + $data['payment_pilibaba_secret_key'] = $this->request->post['payment_pilibaba_secret_key']; + } else { + $data['payment_pilibaba_secret_key'] = $this->config->get('payment_pilibaba_secret_key'); + } + + if (isset($this->request->post['payment_pilibaba_environment'])) { + $data['payment_pilibaba_environment'] = $this->request->post['payment_pilibaba_environment']; + } else { + $data['payment_pilibaba_environment'] = $this->config->get('payment_pilibaba_environment'); + } + + if (isset($this->request->post['payment_pilibaba_shipping_fee'])) { + $data['payment_pilibaba_shipping_fee'] = $this->request->post['payment_pilibaba_shipping_fee']; + } else { + $data['payment_pilibaba_shipping_fee'] = $this->config->get('payment_pilibaba_shipping_fee'); + } + + if (isset($this->request->post['payment_pilibaba_order_status_id'])) { + $data['payment_pilibaba_order_status_id'] = $this->request->post['payment_pilibaba_order_status_id']; + } elseif ($this->config->has('payment_pilibaba_order_status_id')) { + $data['payment_pilibaba_order_status_id'] = $this->config->get('payment_pilibaba_order_status_id'); + } else { + $data['payment_pilibaba_order_status_id'] = '2'; + } + + if (isset($this->request->post['payment_pilibaba_status'])) { + $data['payment_pilibaba_status'] = $this->request->post['payment_pilibaba_status']; + } else { + $data['payment_pilibaba_status'] = $this->config->get('payment_pilibaba_status'); + } + + if (isset($this->request->post['payment_pilibaba_logging'])) { + $data['payment_pilibaba_logging'] = $this->request->post['payment_pilibaba_logging']; + } else { + $data['payment_pilibaba_logging'] = $this->config->get('payment_pilibaba_logging'); + } + + if (isset($this->request->post['payment_pilibaba_sort_order'])) { + $data['payment_pilibaba_sort_order'] = $this->request->post['payment_pilibaba_sort_order']; + } else { + $data['payment_pilibaba_sort_order'] = $this->config->get('payment_pilibaba_sort_order'); + } + + if (isset($this->request->post['payment_pilibaba_email_address'])) { + $data['payment_pilibaba_email_address'] = $this->request->post['payment_pilibaba_email_address']; + } elseif ($this->config->has('payment_pilibaba_email_address')) { + $data['payment_pilibaba_email_address'] = $this->config->get('payment_pilibaba_email_address'); + } else { + $data['payment_pilibaba_email_address'] = ''; + } + + 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->error['pilibaba_merchant_number'])) { + $data['error_pilibaba_merchant_number'] = $this->error['pilibaba_merchant_number']; + } else { + $data['error_pilibaba_merchant_number'] = ''; + } + + if (isset($this->error['pilibaba_secret_key'])) { + $data['error_pilibaba_secret_key'] = $this->error['pilibaba_secret_key']; + } else { + $data['error_pilibaba_secret_key'] = ''; + } + + if (isset($this->error['pilibaba_shipping_fee'])) { + $data['error_pilibaba_shipping_fee'] = $this->error['pilibaba_shipping_fee']; + } else { + $data['error_pilibaba_shipping_fee'] = ''; + } + + if ($data['pilibaba_merchant_number'] && $data['payment_pilibaba_secret_key']) { + $data['show_register'] = false; + + $data['currencies'] = $data['warehouses'] = $data['countries'] = array(); + } else { + $data['show_register'] = true; + + $data['currencies'] = $this->model_extension_payment_pilibaba->getCurrencies(); + + $data['warehouses'] = $this->model_extension_payment_pilibaba->getWarehouses(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if ($this->config->get('config_weight_class_id') != '2') { + $data['error_weight'] = sprintf($this->language->get('error_weight'), $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['error_weight'] = ''; + } + + if ($this->config->has('payment_pilibaba_email_address') && $this->config->get('payment_pilibaba_email_address')) { + $data['notice_email'] = sprintf($this->language->get('text_email'), $this->config->get('payment_pilibaba_email_address')); + } else { + $data['notice_email'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pilibaba', $data)); + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->uninstall(); + } + } + + public function register() { + $this->load->language('extension/payment/pilibaba'); + + $json = array(); + + if (isset($this->request->post['email_address']) && isset($this->request->post['password']) && isset($this->request->post['currency']) && isset($this->request->post['warehouse']) && isset($this->request->post['country']) && isset($this->request->post['environment'])) { + if (utf8_strlen($this->request->post['email_address']) < 1) { + $json['error'] = $this->language->get('error_email_address'); + } else if (!filter_var($this->request->post['email_address'], FILTER_VALIDATE_EMAIL)) { + $json['error'] = $this->language->get('error_email_invalid'); + } else if (utf8_strlen($this->request->post['password']) < 8) { + $json['error'] = $this->language->get('error_password'); + } else if (utf8_strlen($this->request->post['currency']) < 1) { + $json['error'] = $this->language->get('error_currency'); + } else if (utf8_strlen($this->request->post['warehouse']) < 1) { + $json['error'] = $this->language->get('error_warehouse'); + } else if ($this->request->post['warehouse'] == 'other' && utf8_strlen($this->request->post['country']) < 1) { + $json['error'] = $this->language->get('error_country'); + } else { + $this->load->model('extension/payment/pilibaba'); + + $response = $this->model_extension_payment_pilibaba->register($this->request->post['email_address'], $this->request->post['password'], $this->request->post['currency'], $this->request->post['warehouse'], $this->request->post['country'], $this->request->post['environment']); + + if (isset($response['code']) && isset($response['message'])) { + if ($response['code'] == '0') { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('payment_pilibaba', array('pilibaba_merchant_number' => $response['data']['merchantNo'], 'pilibaba_secret_key' => $response['data']['privateKey'], 'pilibaba_email_address' => $this->request->post['email_address'], 'payment_pilibaba_environment' => $this->request->post['environment']), 0); + + $this->session->data['success'] = $this->language->get('text_register_success'); + + $json['redirect'] = $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true); + } else { + $json['error'] = $response['message']; + } + } else { + $json['error'] = $this->language->get('error_bad_response'); + } + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + if ($this->config->get('payment_pilibaba_status')) { + $this->load->model('extension/payment/pilibaba'); + + $order_id = $this->request->get['order_id']; + + $pilibaba_order = $this->model_extension_payment_pilibaba->getOrder($this->request->get['order_id']); + + if ($pilibaba_order) { + $this->load->language('extension/payment/pilibaba'); + + $order_info['order_id'] = $pilibaba_order['order_id']; + + $order_info['amount'] = '¥' . $pilibaba_order['amount']; + + $order_info['fee'] = '¥' . $pilibaba_order['fee']; + + $order_info['status'] = 'Success'; + + $order_info['date_added'] = date($this->language->get('datetime_format'), strtotime($pilibaba_order['date_added'])); + + $order_info['tracking'] = $pilibaba_order['tracking']; + + $data['pilibaba_order'] = $order_info; + + $data['barcode'] = $this->url->link('extension/payment/pilibaba/barcode', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/pilibaba_order', $data); + } + } + } + + public function tracking() { + $this->load->language('extension/payment/pilibaba'); + + $json = array(); + + if ($this->config->get('payment_pilibaba_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['tracking'])) { + if (utf8_strlen($this->request->post['tracking']) > 0 && utf8_strlen($this->request->post['tracking']) <= 50) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->updateTrackingNumber($this->request->post['order_id'], $this->request->post['tracking'], $this->config->get('payment_pilibaba_merchant_number')); + + $json['success'] = $this->language->get('text_tracking_success'); + } else { + $json['error'] = $this->language->get('error_tracking_length'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function barcode() { + if ($this->config->get('payment_pilibaba_status')) { + if (isset($this->request->get['order_id'])) { + if ($this->config->get('payment_pilibaba_environment') == 'live') { + $url = 'https://www.pilibaba.com/pilipay/barCode'; + } else { + $url = 'http://pre.pilibaba.com/pilipay/barCode'; + } + + echo '<img src="' . $url . '?orderNo=' . $this->request->get['order_id'] . '&merchantNo=' . $this->config->get('payment_pilibaba_merchant_number') . '">'; + } + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pilibaba')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pilibaba_merchant_number']) { + $this->error['pilibaba_merchant_number'] = $this->language->get('error_merchant_number'); + } + + if (!$this->request->post['payment_pilibaba_secret_key']) { + $this->error['pilibaba_secret_key'] = $this->language->get('error_secret_key'); + } + + if ($this->request->post['payment_pilibaba_shipping_fee'] != '' && strpos($this->request->post['payment_pilibaba_shipping_fee'], '.') === false) { + $this->error['pilibaba_shipping_fee'] = $this->language->get('error_shipping_fee'); + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_braintree.php b/public/admin/controller/extension/payment/pp_braintree.php new file mode 100644 index 0000000..0bf83e8 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_braintree.php @@ -0,0 +1,1132 @@ +<?php +class ControllerExtensionPaymentPPBraintree extends Controller { + private $error = array(); + private $gateway = null; + private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/connect'; + private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/retrieve'; + + public function index() { + $this->load->language('extension/payment/pp_braintree'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $account) { + if (!isset($account['status'])) { + $this->request->post['payment_pp_braintree_account'][$currency]['status'] = 0; + } + } + + $this->model_setting_setting->editSetting('payment_pp_braintree', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['button_configure'] = $this->url->link('extension/module/pp_braintree_button/configure', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = array(); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_braintree_merchant_id'])) { + $data['payment_pp_braintree_merchant_id'] = $this->request->post['payment_pp_braintree_merchant_id']; + } else { + $data['payment_pp_braintree_merchant_id'] = $this->config->get('payment_pp_braintree_merchant_id'); + } + + if (isset($this->request->post['payment_pp_braintree_public_key'])) { + $data['payment_pp_braintree_public_key'] = $this->request->post['payment_pp_braintree_public_key']; + } else { + $data['payment_pp_braintree_public_key'] = $this->config->get('payment_pp_braintree_public_key'); + } + + if (isset($this->request->post['payment_pp_braintree_private_key'])) { + $data['payment_pp_braintree_private_key'] = $this->request->post['payment_pp_braintree_private_key']; + } else { + $data['payment_pp_braintree_private_key'] = $this->config->get('payment_pp_braintree_private_key'); + } + + if (isset($this->request->post['payment_pp_braintree_access_token'])) { + $data['payment_pp_braintree_access_token'] = $this->request->post['payment_pp_braintree_access_token']; + } else { + $data['payment_pp_braintree_access_token'] = $this->config->get('payment_pp_braintree_access_token'); + } + + if (isset($this->request->post['payment_pp_braintree_refresh_token'])) { + $data['payment_pp_braintree_refresh_token'] = $this->request->post['payment_pp_braintree_refresh_token']; + } else { + $data['payment_pp_braintree_refresh_token'] = $this->config->get('payment_pp_braintree_refresh_token'); + } + + if (isset($this->request->post['payment_pp_braintree_environment'])) { + $data['payment_pp_braintree_environment'] = $this->request->post['payment_pp_braintree_environment']; + } else { + $data['payment_pp_braintree_environment'] = $this->config->get('payment_pp_braintree_environment'); + } + + if (isset($this->request->post['payment_pp_braintree_settlement_immediate'])) { + $data['payment_pp_braintree_settlement_immediate'] = $this->request->post['payment_pp_braintree_settlement_immediate']; + } else { + $data['payment_pp_braintree_settlement_immediate'] = $this->config->get('payment_pp_braintree_settlement_immediate'); + } + + if (isset($this->request->post['payment_pp_braintree_card_vault'])) { + $data['payment_pp_braintree_card_vault'] = $this->request->post['payment_pp_braintree_card_vault']; + } else { + $data['payment_pp_braintree_card_vault'] = $this->config->get('payment_pp_braintree_card_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_card_check_vault'])) { + $data['payment_pp_braintree_card_check_vault'] = $this->request->post['payment_pp_braintree_card_check_vault']; + } else { + $data['payment_pp_braintree_card_check_vault'] = $this->config->get('payment_pp_braintree_card_check_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_vault'])) { + $data['payment_pp_braintree_paypal_vault'] = $this->request->post['payment_pp_braintree_paypal_vault']; + } else { + $data['payment_pp_braintree_paypal_vault'] = $this->config->get('payment_pp_braintree_paypal_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_check_vault'])) { + $data['payment_pp_braintree_paypal_check_vault'] = $this->request->post['payment_pp_braintree_paypal_check_vault']; + } else { + $data['payment_pp_braintree_paypal_check_vault'] = $this->config->get('payment_pp_braintree_paypal_check_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_vault_cvv_3ds'])) { + $data['payment_pp_braintree_vault_cvv_3ds'] = $this->request->post['payment_pp_braintree_vault_cvv_3ds']; + } else { + $data['payment_pp_braintree_vault_cvv_3ds'] = $this->config->get('payment_pp_braintree_vault_cvv_3ds'); + } + + if (isset($this->request->post['payment_pp_braintree_debug'])) { + $data['payment_pp_braintree_debug'] = $this->request->post['payment_pp_braintree_debug']; + } else { + $data['payment_pp_braintree_debug'] = $this->config->get('payment_pp_braintree_debug'); + } + + if (isset($this->request->post['payment_pp_braintree_total'])) { + $data['payment_pp_braintree_total'] = $this->request->post['payment_pp_braintree_total']; + } else { + $data['payment_pp_braintree_total'] = $this->config->get('payment_pp_braintree_total'); + } + + if (isset($this->request->post['payment_pp_braintree_geo_zone_id'])) { + $data['payment_pp_braintree_geo_zone_id'] = $this->request->post['payment_pp_braintree_geo_zone_id']; + } else { + $data['payment_pp_braintree_geo_zone_id'] = $this->config->get('payment_pp_braintree_geo_zone_id'); + } + + if (isset($this->request->post['payment_pp_braintree_status'])) { + $data['payment_pp_braintree_status'] = $this->request->post['payment_pp_braintree_status']; + } else { + $data['payment_pp_braintree_status'] = $this->config->get('payment_pp_braintree_status'); + } + + if (isset($this->request->post['payment_pp_braintree_sort_order'])) { + $data['payment_pp_braintree_sort_order'] = $this->request->post['payment_pp_braintree_sort_order']; + } else { + $data['payment_pp_braintree_sort_order'] = $this->config->get('payment_pp_braintree_sort_order'); + } + + if (isset($this->request->post['payment_pp_braintree_account'])) { + $data['payment_pp_braintree_account'] = $this->request->post['payment_pp_braintree_account']; + } else { + $data['payment_pp_braintree_account'] = $this->config->get('payment_pp_braintree_account'); + } + + if (isset($this->request->post['payment_pp_braintree_authorization_expired_id'])) { + $data['payment_pp_braintree_authorization_expired_id'] = $this->request->post['payment_pp_braintree_authorization_expired_id']; + } else { + $data['payment_pp_braintree_authorization_expired_id'] = $this->config->get('payment_pp_braintree_authorization_expired_id'); + } + + if (isset($this->request->post['payment_pp_braintree_authorized_id'])) { + $data['payment_pp_braintree_authorized_id'] = $this->request->post['payment_pp_braintree_authorized_id']; + } else { + $data['payment_pp_braintree_authorized_id'] = $this->config->get('payment_pp_braintree_authorized_id'); + } + + if (isset($this->request->post['payment_pp_braintree_authorizing_id'])) { + $data['payment_pp_braintree_authorizing_id'] = $this->request->post['payment_pp_braintree_authorizing_id']; + } else { + $data['payment_pp_braintree_authorizing_id'] = $this->config->get('payment_pp_braintree_authorizing_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settlement_pending_id'])) { + $data['payment_pp_braintree_settlement_pending_id'] = $this->request->post['payment_pp_braintree_settlement_pending_id']; + } else { + $data['payment_pp_braintree_settlement_pending_id'] = $this->config->get('payment_pp_braintree_settlement_pending_id'); + } + + if (isset($this->request->post['payment_pp_braintree_failed_id'])) { + $data['payment_pp_braintree_failed_id'] = $this->request->post['payment_pp_braintree_failed_id']; + } else { + $data['payment_pp_braintree_failed_id'] = $this->config->get('payment_pp_braintree_failed_id'); + } + + if (isset($this->request->post['payment_pp_braintree_gateway_rejected_id'])) { + $data['payment_pp_braintree_gateway_rejected_id'] = $this->request->post['payment_pp_braintree_gateway_rejected_id']; + } else { + $data['payment_pp_braintree_gateway_rejected_id'] = $this->config->get('payment_pp_braintree_gateway_rejected_id'); + } + + if (isset($this->request->post['payment_pp_braintree_processor_declined_id'])) { + $data['payment_pp_braintree_processor_declined_id'] = $this->request->post['payment_pp_braintree_processor_declined_id']; + } else { + $data['payment_pp_braintree_processor_declined_id'] = $this->config->get('payment_pp_braintree_processor_declined_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settled_id'])) { + $data['payment_pp_braintree_settled_id'] = $this->request->post['payment_pp_braintree_settled_id']; + } else { + $data['payment_pp_braintree_settled_id'] = $this->config->get('payment_pp_braintree_settled_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settling_id'])) { + $data['payment_pp_braintree_settling_id'] = $this->request->post['payment_pp_braintree_settling_id']; + } else { + $data['payment_pp_braintree_settling_id'] = $this->config->get('payment_pp_braintree_settling_id'); + } + + if (isset($this->request->post['payment_pp_braintree_submitted_for_settlement_id'])) { + $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->request->post['payment_pp_braintree_submitted_for_settlement_id']; + } else { + $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->config->get('payment_pp_braintree_submitted_for_settlement_id'); + } + + if (isset($this->request->post['payment_pp_braintree_voided_id'])) { + $data['payment_pp_braintree_voided_id'] = $this->request->post['payment_pp_braintree_voided_id']; + } else { + $data['payment_pp_braintree_voided_id'] = $this->config->get('payment_pp_braintree_voided_id'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_status'])) { + $data['payment_pp_braintree_3ds_status'] = $this->request->post['payment_pp_braintree_3ds_status']; + } else { + $data['payment_pp_braintree_3ds_status'] = $this->config->get('payment_pp_braintree_3ds_status'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unsupported_card'])) { + $data['payment_pp_braintree_3ds_unsupported_card'] = $this->request->post['payment_pp_braintree_3ds_unsupported_card']; + } else { + $data['payment_pp_braintree_3ds_unsupported_card'] = $this->config->get('payment_pp_braintree_3ds_unsupported_card'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_error'])) { + $data['payment_pp_braintree_3ds_lookup_error'] = $this->request->post['payment_pp_braintree_3ds_lookup_error']; + } else { + $data['payment_pp_braintree_3ds_lookup_error'] = $this->config->get('payment_pp_braintree_3ds_lookup_error'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_enrolled'])) { + $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_enrolled']; + } else { + $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_enrolled'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled'])) { + $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled']; + } else { + $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_not_enrolled'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_not_participating'])) { + $data['payment_pp_braintree_3ds_not_participating'] = $this->request->post['payment_pp_braintree_3ds_not_participating']; + } else { + $data['payment_pp_braintree_3ds_not_participating'] = $this->config->get('payment_pp_braintree_3ds_not_participating'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unavailable'])) { + $data['payment_pp_braintree_3ds_unavailable'] = $this->request->post['payment_pp_braintree_3ds_unavailable']; + } else { + $data['payment_pp_braintree_3ds_unavailable'] = $this->config->get('payment_pp_braintree_3ds_unavailable'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_signature_failed'])) { + $data['payment_pp_braintree_3ds_signature_failed'] = $this->request->post['payment_pp_braintree_3ds_signature_failed']; + } else { + $data['payment_pp_braintree_3ds_signature_failed'] = $this->config->get('payment_pp_braintree_3ds_signature_failed'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_successful'])) { + $data['payment_pp_braintree_3ds_successful'] = $this->request->post['payment_pp_braintree_3ds_successful']; + } else { + $data['payment_pp_braintree_3ds_successful'] = $this->config->get('payment_pp_braintree_3ds_successful'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_attempt_successful'])) { + $data['payment_pp_braintree_3ds_attempt_successful'] = $this->request->post['payment_pp_braintree_3ds_attempt_successful']; + } else { + $data['payment_pp_braintree_3ds_attempt_successful'] = $this->config->get('payment_pp_braintree_3ds_attempt_successful'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_failed'])) { + $data['payment_pp_braintree_3ds_failed'] = $this->request->post['payment_pp_braintree_3ds_failed']; + } else { + $data['payment_pp_braintree_3ds_failed'] = $this->config->get('payment_pp_braintree_3ds_failed'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unable_to_auth'])) { + $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->request->post['payment_pp_braintree_3ds_unable_to_auth']; + } else { + $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->config->get('payment_pp_braintree_3ds_unable_to_auth'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_error'])) { + $data['payment_pp_braintree_3ds_error'] = $this->request->post['payment_pp_braintree_3ds_error']; + } else { + $data['payment_pp_braintree_3ds_error'] = $this->config->get('payment_pp_braintree_3ds_error'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_option'])) { + $data['payment_pp_braintree_paypal_option'] = $this->request->post['payment_pp_braintree_paypal_option']; + } else { + $data['payment_pp_braintree_paypal_option'] = $this->config->get('payment_pp_braintree_paypal_option'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_colour'])) { + $data['payment_pp_braintree_paypal_button_colour'] = $this->request->post['payment_pp_braintree_paypal_button_colour']; + } else { + $data['payment_pp_braintree_paypal_button_colour'] = $this->config->get('payment_pp_braintree_paypal_button_colour'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_size'])) { + $data['payment_pp_braintree_paypal_button_size'] = $this->request->post['payment_pp_braintree_paypal_button_size']; + } else { + $data['payment_pp_braintree_paypal_button_size'] = $this->config->get('payment_pp_braintree_paypal_button_size'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_shape'])) { + $data['payment_pp_braintree_paypal_button_shape'] = $this->request->post['payment_pp_braintree_paypal_button_shape']; + } else { + $data['payment_pp_braintree_paypal_button_shape'] = $this->config->get('payment_pp_braintree_paypal_button_shape'); + } + + if (isset($this->request->post['payment_pp_braintree_billing_agreement'])) { + $data['payment_pp_braintree_billing_agreement'] = $this->request->post['payment_pp_braintree_billing_agreement']; + } else { + $data['payment_pp_braintree_billing_agreement'] = $this->config->get('payment_pp_braintree_billing_agreement'); + } + + $data['transaction_statuses'] = array( + 'authorization_expired', + 'authorized', + 'authorizing', + 'settlement_pending', + 'failed', + 'gateway_rejected', + 'processor_declined', + 'settled', + 'settling', + 'submitted_for_settlement', + 'voided' + ); + + $data['card_types'] = array( + 'Visa', + 'MasterCard', + 'American Express', + 'Discover', + 'JCB', + 'Maestro' + ); + + if (isset($this->request->get['retrieve_code'])) { + $data['retrieve_code'] = $this->request->get['retrieve_code']; + + $curl = curl_init($this->opencart_retrieve_url); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'retrieve_code' => $this->request->get['retrieve_code'], + 'store_version' => VERSION, + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + $config_response = json_decode($curl_response, true); + curl_close($curl); + + if (isset($config_response['merchant_id']) && isset($config_response['access_token']) && isset($config_response['refresh_token'])) { + $braintree_settings = $this->model_setting_setting->getSetting('payment_pp_braintree'); + $braintree_settings['payment_pp_braintree_merchant_id'] = $config_response['merchant_id']; + $braintree_settings['payment_pp_braintree_access_token'] = $config_response['access_token']; + $braintree_settings['payment_pp_braintree_refresh_token'] = $config_response['refresh_token']; + $braintree_settings['payment_pp_braintree_environment'] = $config_response['environment']; + $braintree_settings['payment_pp_braintree_public_key'] = ''; + $braintree_settings['payment_pp_braintree_private_key'] = ''; + + $this->model_setting_setting->editSetting('payment_pp_braintree', $braintree_settings); + + $data['payment_pp_braintree_merchant_id'] = $config_response['merchant_id']; + $data['payment_pp_braintree_access_token'] = $config_response['access_token']; + $data['payment_pp_braintree_refresh_token'] = $config_response['refresh_token']; + $data['payment_pp_braintree_environment'] = $config_response['environment']; + $data['payment_pp_braintree_public_key'] = ''; + $data['payment_pp_braintree_private_key'] = ''; + + $data['success'] = $this->language->get('text_success_connect'); + } + } + + $data['auth_connect_url'] = ''; + + // If Braintree is not setup yet, request auth token for merchant on-boarding flow + if ($data['payment_pp_braintree_merchant_id'] == '') { + $curl = curl_init($this->opencart_connect_url); + + $this->load->model('localisation/country'); + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if ($curl_response['url']) { + $data['auth_connect_url'] = $curl_response['url']; + } + } + + $data['braintree_config'] = array(); + $data['braintree_config']['three_d_secure_enabled'] = 0; + $data['braintree_config']['paypal_enabled'] = 0; + + $data['error_braintree_account_3ds'] = $this->language->get('error_braintree_account_3ds'); + $data['error_braintree_account_paypal'] = $this->language->get('error_braintree_account_paypal'); + + // load the account info from braintree if the config has been added yet. + if (!empty($data['payment_pp_braintree_access_token']) || (!empty($data['payment_pp_braintree_environment']) && !empty($data['payment_pp_braintree_merchant_id']) && !empty($data['payment_pp_braintree_public_key']) && !empty($data['payment_pp_braintree_private_key']))) { + $this->initialise($data['payment_pp_braintree_access_token'], array( + 'payment_pp_braintree_environment' => $data['payment_pp_braintree_environment'], + 'payment_pp_braintree_merchant_id' => $data['payment_pp_braintree_merchant_id'], + 'payment_pp_braintree_public_key' => $data['payment_pp_braintree_public_key'], + 'payment_pp_braintree_private_key' => $data['payment_pp_braintree_private_key'], + )); + + $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } else { + $merchant_config = json_decode(base64_decode($verify_credentials), true); + + if (isset($merchant_config['threeDSecureEnabled']) && $merchant_config['threeDSecureEnabled'] == 1) { + $data['braintree_config']['three_d_secure_enabled'] = 1; + } + + if (isset($merchant_config['paypalEnabled']) && $merchant_config['paypalEnabled'] == 1) { + $data['braintree_config']['paypal_enabled'] = 1; + } + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_braintree', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $defaults = array(); + + // 3D secure defaults + $defaults['payment_pp_braintree_3ds_unsupported_card'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_error'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_enrolled'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_not_enrolled'] = 1; + $defaults['payment_pp_braintree_3ds_not_participating'] = 1; + $defaults['payment_pp_braintree_3ds_unavailable'] = 1; + $defaults['payment_pp_braintree_3ds_signature_failed'] = 0; + $defaults['payment_pp_braintree_3ds_successful'] = 1; + $defaults['payment_pp_braintree_3ds_attempt_successful'] = 1; + $defaults['payment_pp_braintree_3ds_failed'] = 0; + $defaults['payment_pp_braintree_3ds_unable_to_auth'] = 1; + $defaults['payment_pp_braintree_3ds_error'] = 1; + + // Order Status defaults + $defaults['payment_pp_braintree_authorization_expired_id'] = 14; + $defaults['payment_pp_braintree_authorized_id'] = 2; + $defaults['payment_pp_braintree_authorizing_id'] = 1; + $defaults['payment_pp_braintree_failed_id'] = 10; + $defaults['payment_pp_braintree_gateway_rejected_id'] = 8; + $defaults['payment_pp_braintree_processor_declined_id'] = 8; + $defaults['payment_pp_braintree_settled_id'] = 2; + $defaults['payment_pp_braintree_settling_id'] = 2; + $defaults['payment_pp_braintree_settlement_pending_id'] = 2; + $defaults['payment_pp_braintree_submitted_for_settlement_id'] = 2; + $defaults['payment_pp_braintree_voided_id'] = 16; + + $defaults['payment_pp_braintree_settlement_immediate'] = 1; + + // PayPal options + $defaults['payment_pp_braintree_paypal_option'] = 1; + $defaults['payment_pp_braintree_paypal_button_size'] = 'small'; + $defaults['payment_pp_braintree_paypal_button_shape'] = 'rect'; + + // Vault options + $defaults['payment_pp_braintree_card_vault'] = 1; + $defaults['payment_pp_braintree_paypal_vault'] = 0; + $defaults['payment_pp_braintree_card_check_vault'] = 1; + $defaults['payment_pp_braintree_paypal_check_vault'] = 0; + + $this->model_setting_setting->editSetting('payment_pp_braintree', $defaults); + } + + public function order() { + $this->load->language('extension/payment/pp_braintree'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/pp_braintree_order', $data); + } + + public function getTransaction() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + $this->load->model('sale/order'); + + if (!$this->config->get('payment_pp_braintree_status') || (!isset($this->request->get['order_id']) && !isset($this->request->get['transaction_id']))) { + return; + } + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + if (isset($this->request->get['order_id'])) { + $search = array( + Braintree_TransactionSearch::orderId()->is($this->request->get['order_id']) + ); + } elseif (isset($this->request->get['transaction_id'])) { + $search = array( + Braintree_TransactionSearch::id()->is($this->request->get['transaction_id']) + ); + } + + $search_transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search); + + $transaction = array(); + + foreach ($search_transactions as $search_transaction) { + $transaction = $search_transaction; + } + + $data['transaction'] = array(); + + if ($transaction) { + $data['transaction_id'] = $transaction->id; + + $data['user_token'] = $this->session->data['user_token']; + + $data['void_action'] = $data['settle_action'] = $data['refund_action'] = false; + + switch ($transaction->status) { + case 'authorized': + $data['void_action'] = true; + $data['settle_action'] = true; + break; + case 'submitted_for_settlement': + $data['void_action'] = true; + break; + case 'settling': + $data['refund_action'] = true; + break; + case 'settled': + $data['refund_action'] = true; + break; + } + + $statuses = array(); + + foreach ($transaction->statusHistory as $status_history) { + $created_at = $status_history->timestamp; + + $statuses[] = array( + 'status' => $status_history->status, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))) + ); + } + + $data['statuses'] = $statuses; + + $max_settle_amount = $transaction->amount; + + $max_refund_amount = $transaction->amount; + + $data['refunds'] = array(); + + foreach (array_reverse($transaction->refundIds) as $refund_id) { + $refund = $this->model_extension_payment_pp_braintree->getTransaction($this->gateway, $refund_id); + + $successful_statuses = array( + 'authorized', + 'authorizing', + 'settlement_pending', + 'settlement_confirmed', + 'settled', + 'settling', + 'submitted_for_settlement' + ); + + if (in_array($refund->status, $successful_statuses)) { + $max_refund_amount -= $refund->amount; + } + + $created_at = $refund->createdAt; + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))), + 'amount' => $this->currency->format($refund->amount, $refund->currencyIsoCode, '1.00000000', true), + 'status' => $refund->status + ); + } + + //If nothing left to refund, disable refund action + if (!$max_refund_amount) { + $data['refund_action'] = false; + } + + $data['max_settle_amount'] = $this->currency->format($max_settle_amount, $transaction->currencyIsoCode, '1.00000000', false); + + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $transaction->currencyIsoCode, '1.00000000', false); + + $amount = $this->currency->format($transaction->amount, $transaction->currencyIsoCode, '1.00000000', true); + + $data['symbol_left'] = $this->currency->getSymbolLeft($transaction->currencyIsoCode); + $data['symbol_right'] = $this->currency->getSymbolRight($transaction->currencyIsoCode); + + $created_at = $transaction->createdAt; + + if ($transaction->threeDSecureInfo) { + if ($transaction->threeDSecureInfo->liabilityShifted) { + $liability_shifted = $this->language->get('text_yes'); + } else { + $liability_shifted = $this->language->get('text_no'); + } + } + + if ($transaction->threeDSecureInfo) { + if ($transaction->threeDSecureInfo->liabilityShiftPossible) { + $liability_shift_possible = $this->language->get('text_yes'); + } else { + $liability_shift_possible = $this->language->get('text_no'); + } + } + + $data['transaction'] = array( + 'status' => $transaction->status, + 'transaction_id' => $transaction->id, + 'type' => $transaction->type, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))), + 'merchant_account_id' => $transaction->merchantAccountId, + 'payment_type' => $transaction->paymentInstrumentType, + 'currency' => $transaction->currencyIsoCode, + 'amount' => $amount, + 'order_id' => $transaction->orderId, + 'processor_code' => $transaction->processorAuthorizationCode, + 'cvv_response' => $transaction->cvvResponseCode, + 'avs_response' => sprintf($this->language->get('text_avs_response'), $transaction->avsStreetAddressResponseCode, $transaction->avsPostalCodeResponseCode), + 'threeds_enrolled' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->enrolled : ''), + 'threeds_status' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->status : ''), + 'threeds_shifted' => ($transaction->threeDSecureInfo ? $liability_shifted : ''), + 'threeds_shift_possible' => ($transaction->threeDSecureInfo ? $liability_shift_possible : '') + ); + + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_settle'] = $this->language->get('text_confirm_settle'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + + $this->response->setOutput($this->load->view('extension/payment/pp_braintree_order_ajax', $data)); + } + } + + public function transactionCommand() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + $json = array(); + + $success = $error = ''; + + if ($this->request->post['type'] == 'void') { + $action = $this->model_extension_payment_pp_braintree->voidTransaction($this->gateway, $this->request->post['transaction_id']); + } elseif ($this->request->post['type'] == 'settle' && $this->request->post['amount']) { + $action = $this->model_extension_payment_pp_braintree->settleTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']); + } elseif ($this->request->post['type'] == 'refund' && $this->request->post['amount']) { + $action = $this->model_extension_payment_pp_braintree->refundTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']); + } else { + $error = true; + } + + if (!$error && $action && $action->success) { + $success = $this->language->get('text_success_action'); + } elseif (!$error && $action && isset($action->message)) { + $error = sprintf($this->language->get('text_error_settle'), $action->message); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function search() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + $this->load->model('customer/customer'); + $this->load->model('sale/order'); + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + $json = array(); + + $success = $error = ''; + + if (isset($this->request->get['filter_transaction_id'])) { + $filter_transaction_id = $this->request->get['filter_transaction_id']; + } else { + $filter_transaction_id = null; + } + + if (isset($this->request->get['filter_transaction_type'])) { + $filter_transaction_type = $this->request->get['filter_transaction_type']; + } else { + $filter_transaction_type = null; + } + + if (isset($this->request->get['filter_payment_type'])) { + $filter_payment_type = $this->request->get['filter_payment_type']; + } else { + $filter_payment_type = null; + } + + if (isset($this->request->get['filter_card_type'])) { + $filter_card_type = $this->request->get['filter_card_type']; + } else { + $filter_card_type = null; + } + + if (isset($this->request->get['filter_merchant_account_id'])) { + $filter_merchant_account_id = $this->request->get['filter_merchant_account_id']; + } else { + $filter_merchant_account_id = null; + } + + if (isset($this->request->get['filter_transaction_status'])) { + $filter_transaction_status = $this->request->get['filter_transaction_status']; + } else { + $filter_transaction_status = null; + } + + if (isset($this->request->get['filter_date_from'])) { + $filter_date_from = $this->request->get['filter_date_from']; + } else { + $filter_date_from = null; + } + + if (isset($this->request->get['filter_date_to'])) { + $filter_date_to = $this->request->get['filter_date_to']; + } else { + $filter_date_to = null; + } + + if (isset($this->request->get['filter_amount_from'])) { + $filter_amount_from = $this->request->get['filter_amount_from']; + } else { + $filter_amount_from = null; + } + + if (isset($this->request->get['filter_amount_to'])) { + $filter_amount_to = $this->request->get['filter_amount_to']; + } else { + $filter_amount_to = null; + } + + $json['transactions'] = array(); + + $search = array(); + + if ($filter_transaction_id) { + $search[] = Braintree_TransactionSearch::id()->is($filter_transaction_id); + } + + if ($filter_transaction_type) { + if ($filter_transaction_type == 'sale') { + $transaction_type = Braintree_Transaction::SALE; + } elseif ($filter_transaction_type == 'credit') { + $transaction_type = Braintree_Transaction::CREDIT; + } + + $search[] = Braintree_TransactionSearch::type()->is($transaction_type); + } + + if ($filter_payment_type) { + if ($filter_payment_type == 'Credit Card') { + $payment_type = 'CreditCardDetail'; + } elseif ($filter_payment_type == 'PayPal') { + $payment_type = 'PayPalDetail'; + } + + $search[] = Braintree_TransactionSearch::paymentInstrumentType()->is($payment_type); + } + + if ($filter_card_type) { + switch ($filter_card_type) { + case 'Visa': + $card_type = Braintree_CreditCard::VISA; + break; + case 'MasterCard': + $card_type = Braintree_CreditCard::MASTER_CARD; + break; + case 'American Express': + $card_type = Braintree_CreditCard::AMEX; + break; + case 'Discover': + $card_type = Braintree_CreditCard::DISCOVER; + break; + case 'JCB': + $card_type = Braintree_CreditCard::JCB; + break; + case 'Maestro': + $card_type = Braintree_CreditCard::MAESTRO; + break; + } + + $search[] = Braintree_TransactionSearch::creditCardCardType()->is($card_type); + } + + if ($filter_merchant_account_id) { + $search[] = Braintree_TransactionSearch::merchantAccountId()->is($filter_merchant_account_id); + } + + if ($filter_transaction_status) { + $search[] = Braintree_TransactionSearch::status()->in($filter_transaction_status); + } + + if ($filter_date_from || $filter_date_to) { + if ($filter_date_from) { + $date_from = new DateTime($filter_date_from); + } else { + $date_from = new DateTime('2012-01-01 00:00'); + } + + if ($filter_date_to) { + $date_to = new DateTime($filter_date_to . ' +1 day -1 minute'); + } else { + $date_to = new DateTime('tomorrow -1 minute'); + } + + $search[] = Braintree_TransactionSearch::createdAt()->between($date_from, $date_to); + } + + if ($filter_amount_from) { + $amount_from = $filter_amount_from; + } else { + $amount_from = 0; + } + + if ($filter_amount_to) { + $amount_to = $filter_amount_to; + } else { + $amount_to = 9999999; + } + + $search[] = Braintree_TransactionSearch::amount()->between((float)$amount_from, (float)$amount_to); + + $transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search); + + if ($transactions) { + foreach ($transactions as $transaction) { + $customer_url = false; + + if ($transaction->customer['id']) { + $braintree_customer_id = explode('_', $transaction->customer['id']); + + if (isset($braintree_customer_id[2]) && is_numeric($braintree_customer_id[2])) { + $customer_info = $this->model_customer_customer->getCustomer($braintree_customer_id[2]); + + if ($customer_info && $customer_info['email'] == $transaction->customer['email']) { + $customer_url = $this->url->link('sale/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$braintree_customer_id[2], true); + } + } + } + + $order = false; + + if ($transaction->orderId) { + $order_info = $this->model_sale_order->getOrder($transaction->orderId); + + if ($order_info && $order_info['email'] == $transaction->customer['email']) { + $order = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$transaction->orderId, true); + } + } + + $created_at = $transaction->createdAt; + + $json['transactions'][] = array( + 'transaction_id' => $transaction->id, + 'amount' => $transaction->amount, + 'currency_iso' => $transaction->currencyIsoCode, + 'status' => $transaction->status, + 'type' => $transaction->type, + 'merchant_account_id' => $transaction->merchantAccountId, + 'customer' => $transaction->customer['firstName'] . ' ' . $transaction->customer['lastName'], + 'customer_url' => $customer_url, + 'order' => $order, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function connectRedirect() { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + // Install the module before doing the redirect + $this->load->model('setting/extension'); + + $this->model_setting_extension->install('payment', 'pp_braintree'); + + $this->install(); + + $curl = curl_init($this->opencart_connect_url); + + $this->load->model('localisation/country'); + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if ($curl_response['url']) { + $this->response->redirect($curl_response['url']); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function promotion() { + $this->load->language('extension/payment/pp_braintree'); + + $data['connect_link'] = ''; + $data['module_link'] = ''; + + if ($this->config->get('payment_pp_braintree_status') || $this->config->get('payment_pp_braintree_merchant_id') || $this->config->get('payment_pp_braintree_access_token')) { + $data['module_link'] = $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true); + } else { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + $data['connect_link'] = $this->url->link('extension/payment/pp_braintree/connectRedirect', 'user_token=' . $this->session->data['user_token'], true); + } + } + + if ($this->config->get("payment_pp_braintree_status") == 1) { + $data['payment_pp_braintree_status'] = "enabled"; + } elseif ($this->config->get("payment_pp_braintree_status") == null) { + $data['payment_pp_braintree_status'] = ""; + } else { + $data['payment_pp_braintree_status'] = "disabled"; + } + + return $this->load->view('extension/payment/pp_braintree_promotion', $data); + } + + protected function validate() { + $this->load->model('extension/payment/pp_braintree'); + + $check_credentials = true; + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/pp_braintree')) { + $this->error['warning'] = $this->language->get('error_permission'); + + $check_credentials = false; + } + + if ($check_credentials && $this->request->post['payment_pp_braintree_status'] == 1) { + $this->initialise($this->request->post['payment_pp_braintree_access_token'], array( + 'payment_pp_braintree_environment' => $this->request->post['payment_pp_braintree_environment'], + 'payment_pp_braintree_merchant_id' => $this->request->post['payment_pp_braintree_merchant_id'], + 'payment_pp_braintree_public_key' => $this->request->post['payment_pp_braintree_public_key'], + 'payment_pp_braintree_private_key' => $this->request->post['payment_pp_braintree_private_key'], + )); + + $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } else { + foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $pp_braintree_account) { + if (!empty($pp_braintree_account['merchant_account_id'])) { + $verify_merchant_account_id = $this->model_extension_payment_pp_braintree->verifyMerchantAccount($this->gateway, $pp_braintree_account['merchant_account_id']); + + if (!$verify_merchant_account_id) { + $this->error['account'][$currency] = $this->language->get('error_account'); + } + } + } + + $merchant_config = json_decode(base64_decode($verify_credentials), true); + + // verify the Braintree account is ready to accept 3DS transactions + if (isset($merchant_config['threeDSecureEnabled']) && ($this->request->post['payment_pp_braintree_3ds_status'] == 1 && $merchant_config['threeDSecureEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_3ds_not_ready'); + } + + // verify the Braintree account is ready to use PayPal Billing Agreements + if (isset($merchant_config['paypal']['billingAgreementEnabled']) && ($this->request->post['payment_pp_braintree_billing_agreement'] == 1 && $merchant_config['paypal']['billingAgreementEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_paypal_billing_not_ready'); + } + + // verify the Braintree account is ready to accept PayPal transactions + if (isset($merchant_config['paypalEnabled']) && ($this->request->post['payment_pp_braintree_paypal_option'] == 1 && $merchant_config['paypalEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_paypal_not_ready'); + } + + // verify the environment matches with the token the system is using + if (isset($merchant_config['environment']) && ($this->request->post['payment_pp_braintree_environment'] != $merchant_config['environment'])) { + $this->error['warning'] = sprintf($this->language->get('error_environment'), $this->request->post['payment_pp_braintree_environment'], $merchant_config['environment']); + } + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + private function initialise($access_token = '', $credentials = array()) { + $this->load->model('extension/payment/pp_braintree'); + + if ($access_token != '') { + $this->gateway = $this->model_extension_payment_pp_braintree->setGateway($access_token); + } else { + Braintree_Configuration::environment(isset($credentials['payment_pp_braintree_environment']) ? $credentials['payment_pp_braintree_environment'] : ''); + Braintree_Configuration::merchantId(isset($credentials['payment_pp_braintree_merchant_id']) ? $credentials['payment_pp_braintree_merchant_id'] : ''); + Braintree_Configuration::publicKey(isset($credentials['payment_pp_braintree_public_key']) ? $credentials['payment_pp_braintree_public_key'] : ''); + Braintree_Configuration::privateKey(isset($credentials['payment_pp_braintree_private_key']) ? $credentials['payment_pp_braintree_private_key'] : ''); + } + } +} diff --git a/public/admin/controller/extension/payment/pp_express.php b/public/admin/controller/extension/payment/pp_express.php new file mode 100644 index 0000000..aed25c0 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_express.php @@ -0,0 +1,1347 @@ +<?php +class ControllerExtensionPaymentPPExpress extends Controller { + private $error = array(); + private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/connect'; + private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/retrieve'; + + public function index() { + $this->load->language('extension/payment/pp_express'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_express', $this->request->post); + + // If OC has been upgraded, verify that the module has the new event registered. + $this->load->model('setting/event'); + + $pp_express_js_event = $this->model_setting_event->getEventByCode("extension_pp_express_checkout_js"); + + if (empty($pp_express_js_event)) { + // Event is missing, add it + $this->model_setting_event->addEvent('extension_pp_express_checkout_js', 'catalog/controller/checkout/checkout/before', 'extension/payment/pp_express/eventLoadCheckoutJs'); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['button_configure'] = $this->url->link('extension/module/pp_button/configure', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + if (isset($this->error['sandbox_username'])) { + $data['error_sandbox_username'] = $this->error['sandbox_username']; + } else { + $data['error_sandbox_username'] = ''; + } + + if (isset($this->error['sandbox_password'])) { + $data['error_sandbox_password'] = $this->error['sandbox_password']; + } else { + $data['error_sandbox_password'] = ''; + } + + if (isset($this->error['sandbox_signature'])) { + $data['error_sandbox_signature'] = $this->error['sandbox_signature']; + } else { + $data['error_sandbox_signature'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['search'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['payment_pp_express_username'])) { + $data['payment_pp_express_username'] = $this->request->post['payment_pp_express_username']; + } else { + $data['payment_pp_express_username'] = $this->config->get('payment_pp_express_username'); + } + + if (isset($this->request->post['payment_pp_express_password'])) { + $data['payment_pp_express_password'] = $this->request->post['payment_pp_express_password']; + } else { + $data['payment_pp_express_password'] = $this->config->get('payment_pp_express_password'); + } + + if (isset($this->request->post['payment_pp_express_signature'])) { + $data['payment_pp_express_signature'] = $this->request->post['payment_pp_express_signature']; + } else { + $data['payment_pp_express_signature'] = $this->config->get('payment_pp_express_signature'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_username'])) { + $data['payment_pp_express_sandbox_username'] = $this->request->post['payment_pp_express_sandbox_username']; + } else { + $data['payment_pp_express_sandbox_username'] = $this->config->get('payment_pp_express_sandbox_username'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_password'])) { + $data['payment_pp_express_sandbox_password'] = $this->request->post['payment_pp_express_sandbox_password']; + } else { + $data['payment_pp_express_sandbox_password'] = $this->config->get('payment_pp_express_sandbox_password'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_signature'])) { + $data['payment_pp_express_sandbox_signature'] = $this->request->post['payment_pp_express_sandbox_signature']; + } else { + $data['payment_pp_express_sandbox_signature'] = $this->config->get('payment_pp_express_sandbox_signature'); + } + + if (isset($this->request->post['payment_pp_express_test'])) { + $data['payment_pp_express_test'] = $this->request->post['payment_pp_express_test']; + } else { + $data['payment_pp_express_test'] = $this->config->get('payment_pp_express_test'); + } + + if (isset($this->request->post['payment_pp_express_debug'])) { + $data['payment_pp_express_debug'] = $this->request->post['payment_pp_express_debug']; + } else { + $data['payment_pp_express_debug'] = $this->config->get('payment_pp_express_debug'); + } + + if (isset($this->request->post['payment_pp_express_currency'])) { + $data['payment_pp_express_currency'] = $this->request->post['payment_pp_express_currency']; + } else { + $data['payment_pp_express_currency'] = $this->config->get('payment_pp_express_currency'); + } + + if (isset($this->request->post['payment_pp_express_recurring_cancel'])) { + $data['payment_pp_express_recurring_cancel'] = $this->request->post['payment_pp_express_recurring_cancel']; + } else { + $data['payment_pp_express_recurring_cancel'] = $this->config->get('payment_pp_express_recurring_cancel'); + } + + if (isset($this->request->post['payment_pp_express_transaction'])) { + $data['payment_pp_express_transaction'] = $this->request->post['payment_pp_express_transaction']; + } else { + $data['payment_pp_express_transaction'] = $this->config->get('payment_pp_express_transaction'); + } + + if (isset($this->request->post['payment_pp_express_total'])) { + $data['payment_pp_express_total'] = $this->request->post['payment_pp_express_total']; + } else { + $data['payment_pp_express_total'] = $this->config->get('payment_pp_express_total'); + } + + if (isset($this->request->post['payment_pp_express_geo_zone_id'])) { + $data['payment_pp_express_geo_zone_id'] = $this->request->post['payment_pp_express_geo_zone_id']; + } else { + $data['payment_pp_express_geo_zone_id'] = $this->config->get('payment_pp_express_geo_zone_id'); + } + + if (isset($this->request->post['payment_pp_express_status'])) { + $data['payment_pp_express_status'] = $this->request->post['payment_pp_express_status']; + } else { + $data['payment_pp_express_status'] = $this->config->get('payment_pp_express_status'); + } + + if (isset($this->request->post['payment_pp_express_sort_order'])) { + $data['payment_pp_express_sort_order'] = $this->request->post['payment_pp_express_sort_order']; + } else { + $data['payment_pp_express_sort_order'] = $this->config->get('payment_pp_express_sort_order'); + } + + if (isset($this->request->post['payment_pp_express_canceled_reversal_status_id'])) { + $data['payment_pp_express_canceled_reversal_status_id'] = $this->request->post['payment_pp_express_canceled_reversal_status_id']; + } else { + $data['payment_pp_express_canceled_reversal_status_id'] = $this->config->get('payment_pp_express_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_express_completed_status_id'])) { + $data['payment_pp_express_completed_status_id'] = $this->request->post['payment_pp_express_completed_status_id']; + } else { + $data['payment_pp_express_completed_status_id'] = $this->config->get('payment_pp_express_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_denied_status_id'])) { + $data['payment_pp_express_denied_status_id'] = $this->request->post['payment_pp_express_denied_status_id']; + } else { + $data['payment_pp_express_denied_status_id'] = $this->config->get('payment_pp_express_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_express_expired_status_id'])) { + $data['payment_pp_express_expired_status_id'] = $this->request->post['payment_pp_express_expired_status_id']; + } else { + $data['payment_pp_express_expired_status_id'] = $this->config->get('payment_pp_express_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_express_failed_status_id'])) { + $data['payment_pp_express_failed_status_id'] = $this->request->post['payment_pp_express_failed_status_id']; + } else { + $data['payment_pp_express_failed_status_id'] = $this->config->get('payment_pp_express_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_pending_status_id'])) { + $data['payment_pp_express_pending_status_id'] = $this->request->post['payment_pp_express_pending_status_id']; + } else { + $data['payment_pp_express_pending_status_id'] = $this->config->get('payment_pp_express_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_express_processed_status_id'])) { + $data['payment_pp_express_processed_status_id'] = $this->request->post['payment_pp_express_processed_status_id']; + } else { + $data['payment_pp_express_processed_status_id'] = $this->config->get('payment_pp_express_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_refunded_status_id'])) { + $data['payment_pp_express_refunded_status_id'] = $this->request->post['payment_pp_express_refunded_status_id']; + } else { + $data['payment_pp_express_refunded_status_id'] = $this->config->get('payment_pp_express_refunded_status_id'); + } + + if (isset($this->request->post['payment_pp_express_reversed_status_id'])) { + $data['payment_pp_express_reversed_status_id'] = $this->request->post['payment_pp_express_reversed_status_id']; + } else { + $data['payment_pp_express_reversed_status_id'] = $this->config->get('payment_pp_express_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_voided_status_id'])) { + $data['payment_pp_express_voided_status_id'] = $this->request->post['payment_pp_express_voided_status_id']; + } else { + $data['payment_pp_express_voided_status_id'] = $this->config->get('payment_pp_express_voided_status_id'); + } + + + + + + + + if (isset($this->request->post['payment_pp_express_style_layout'])) { + $data['payment_pp_express_style_layout'] = $this->request->post['payment_pp_express_style_layout']; + } else { + $data['payment_pp_express_style_layout'] = $this->config->get('payment_pp_express_style_layout'); + } + + if (isset($this->request->post['payment_pp_express_style_size'])) { + $data['payment_pp_express_style_size'] = $this->request->post['payment_pp_express_style_size']; + } else { + $data['payment_pp_express_style_size'] = $this->config->get('payment_pp_express_style_size'); + } + + if (isset($this->request->post['payment_pp_express_style_shape'])) { + $data['payment_pp_express_style_shape'] = $this->request->post['payment_pp_express_style_shape']; + } else { + $data['payment_pp_express_style_shape'] = $this->config->get('payment_pp_express_style_shape'); + } + + if (isset($this->request->post['payment_pp_express_style_color'])) { + $data['payment_pp_express_style_color'] = $this->request->post['payment_pp_express_style_color']; + } else { + $data['payment_pp_express_style_color'] = $this->config->get('payment_pp_express_style_color'); + } + + if (isset($this->request->post['payment_pp_express_pp_credit'])) { + $data['payment_pp_express_pp_credit'] = $this->request->post['payment_pp_express_pp_credit']; + } else { + // get the store country id from settings - if it is US then pp_credit is defaulted to on. + if ($this->config->get('payment_pp_express_pp_credit') == null) { + $this->load->model('localisation/country'); + + $store_country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + if (!empty($store_country) && $store_country['iso_code_2'] == "US") { + $data['payment_pp_express_pp_credit'] = 1; + } else { + $data['payment_pp_express_pp_credit'] = 0; + } + } else { + $data['payment_pp_express_pp_credit'] = $this->config->get('payment_pp_express_pp_credit'); + } + } + + if (isset($this->request->post['payment_pp_express_pp_cards'])) { + $data['payment_pp_express_pp_cards'] = $this->request->post['payment_pp_express_pp_cards']; + } else { + $data['payment_pp_express_pp_cards'] = $this->config->get('payment_pp_express_pp_cards'); + } + + if (isset($this->request->post['payment_pp_express_pp_elv'])) { + $data['payment_pp_express_pp_elv'] = $this->request->post['payment_pp_express_pp_elv']; + } else { + $data['payment_pp_express_pp_elv'] = $this->config->get('payment_pp_express_pp_elv'); + } + + if (isset($this->request->post['payment_pp_express_logo'])) { + $data['payment_pp_express_logo'] = $this->request->post['payment_pp_express_logo']; + } else { + $data['payment_pp_express_logo'] = $this->config->get('payment_pp_express_logo'); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_express/ipn'; + + $this->load->model('extension/payment/pp_express'); + $this->load->model('tool/image'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['currencies'] = $this->model_extension_payment_pp_express->getCurrencies(); + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_express_logo']) && is_file(DIR_IMAGE . $this->request->post['payment_pp_express_logo'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['payment_pp_express_logo'], 750, 90); + } elseif (is_file(DIR_IMAGE . $this->config->get('payment_pp_express_logo'))) { + $data['thumb'] = $this->model_tool_image->resize($this->config->get('payment_pp_express_logo'), 750, 90); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 750, 90); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 750, 90); + + if (isset($this->request->get['retrieve_code']) && isset($this->request->get['merchant_id'])) { + $curl = curl_init($this->opencart_retrieve_url); + + $post_data = array( + 'merchant_id' => $this->request->get['merchant_id'], + 'retrieve_code' => $this->request->get['retrieve_code'], + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + $config_response = json_decode($curl_response, true); + curl_close($curl); + + if (isset($config_response['api_user_name']) && isset($config_response['api_password']) && isset($config_response['signature'])) { + $pp_express_settings = $this->model_setting_setting->getSetting('payment_pp_express'); + + if ($config_response['environment'] == 'sandbox') { + $pp_express_settings['payment_pp_express_sandbox_username'] = $config_response['api_user_name']; + $pp_express_settings['payment_pp_express_sandbox_password'] = $config_response['api_password']; + $pp_express_settings['payment_pp_express_sandbox_signature'] = $config_response['signature']; + $pp_express_settings['payment_pp_express_test'] = 1; + + $data['payment_pp_express_sandbox_username'] = $config_response['api_user_name']; + $data['payment_pp_express_sandbox_password'] = $config_response['api_password']; + $data['payment_pp_express_sandbox_signature'] = $config_response['signature']; + $data['payment_pp_express_test'] = 1; + } else { + $pp_express_settings['payment_pp_express_username'] = $config_response['api_user_name']; + $pp_express_settings['payment_pp_express_password'] = $config_response['api_password']; + $pp_express_settings['payment_pp_express_signature'] = $config_response['signature']; + $pp_express_settings['payment_pp_express_test'] = 0; + + $data['payment_pp_express_username'] = $config_response['api_user_name']; + $data['payment_pp_express_password'] = $config_response['api_password']; + $data['payment_pp_express_signature'] = $config_response['signature']; + $data['payment_pp_express_test'] = 0; + } + + $data['retrieve_success'] = 1; + $data['text_retrieve'] = $this->language->get('text_retrieve'); + + $this->model_setting_setting->editSetting('payment_pp_express', $pp_express_settings); + } + } + + $this->load->model('localisation/country'); + + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + // Create sandbox link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'sandbox'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + $data['auth_connect_url_sandbox'] = ''; + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $data['auth_connect_url_sandbox'] = $curl_response['url']; + } + + // Create Live link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'live'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + $data['auth_connect_url_live'] = ''; + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $data['auth_connect_url_live'] = $curl_response['url']; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_express')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['payment_pp_express_test']) { + if (!$this->request->post['payment_pp_express_sandbox_username']) { + $this->error['sandbox_username'] = $this->language->get('error_sandbox_username'); + } + + if (!$this->request->post['payment_pp_express_sandbox_password']) { + $this->error['sandbox_password'] = $this->language->get('error_sandbox_password'); + } + + if (!$this->request->post['payment_pp_express_sandbox_signature']) { + $this->error['sandbox_signature'] = $this->language->get('error_sandbox_signature'); + } + } else { + if (!$this->request->post['payment_pp_express_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_pp_express_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_express_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/payment/pp_express'); + + $this->model_extension_payment_pp_express->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_express'); + + $this->model_extension_payment_pp_express->uninstall(); + } + + public function order() { + if ($this->config->get('payment_pp_express_status')) { + $this->load->language('extension/payment/pp_express_order'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getPayPalOrder($order_id); + + if ($paypal_info) { + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['capture_status'] = $paypal_info['capture_status']; + + $data['total'] = $paypal_info['total']; + + $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2); + + $data['captured'] = $captured; + + $data['capture_remaining'] = number_format($paypal_info['total'] - $captured, 2); + + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2); + + $data['refunded'] = $refunded; + + return $this->load->view('extension/payment/pp_express_order', $data); + } + } + } + + public function transaction() { + $this->load->language('extension/payment/pp_express_order'); + + $data['transactions'] = array(); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + $results = $this->model_extension_payment_pp_express->getTransactions($paypal_info['paypal_order_id']); + + foreach ($results as $result) { + $data['transactions'][] = array( + 'transaction_id' => $result['transaction_id'], + 'amount' => $result['amount'], + 'payment_type' => $result['payment_type'], + 'payment_status' => $result['payment_status'], + 'pending_reason' => $result['pending_reason'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), + 'view' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true), + 'refund' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true), + 'resend' => $this->url->link('extension/payment/pp_express/resend', 'user_token=' . $this->session->data['user_token'] . '&paypal_order_transaction_id=' . $result['paypal_order_transaction_id'], true) + ); + } + } + + $this->response->setOutput($this->load->view('extension/payment/pp_express_transaction', $data)); + } + + public function capture() { + $json = array(); + + $this->load->language('extension/payment/pp_express_order'); + + if (!isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $json['error'] = $this->language->get('error_capture'); + } + + if (!$json) { + $this->load->model('extension/payment/pp_express'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + // If this is the final amount to capture or not + if ($this->request->post['complete'] == 1) { + $complete = 'Complete'; + } else { + $complete = 'NotComplete'; + } + + $request = array( + 'METHOD' => 'DoCapture', + 'AUTHORIZATIONID' => $paypal_info['authorization_id'], + 'AMT' => number_format($this->request->post['amount'], 2), + 'CURRENCYCODE' => $paypal_info['currency_code'], + 'COMPLETETYPE' => $complete, + 'MSGSUBID' => uniqid(mt_rand(), true) + ); + + $response = $this->model_extension_payment_pp_express->call($request); + + if (isset($response['ACK']) && ($response['ACK'] != 'Failure') && ($response['ACK'] != 'FailureWithWarning')) { + $transaction_data = array( + 'paypal_order_id' => $paypal_info['paypal_order_id'], + 'transaction_id' => $response['TRANSACTIONID'], + 'parent_id' => $paypal_info['authorization_id'], + 'note' => '', + 'msgsubid' => $response['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => $response['PAYMENTTYPE'], + 'payment_status' => $response['PAYMENTSTATUS'], + 'pending_reason' => (isset($response['PENDINGREASON']) ? $response['PENDINGREASON'] : ''), + 'transaction_entity' => 'payment', + 'amount' => $response['AMT'], + 'debug_data' => json_encode($response) + ); + + $this->model_extension_payment_pp_express->addTransaction($transaction_data); + + $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2); + + $json['captured'] = $captured; + $json['refunded'] = $refunded; + $json['remaining'] = number_format($paypal_info['total'] - $captured, 2); + + if ($this->request->post['complete'] == 1 || $json['remaining'] == 0.00) { + $json['capture_status'] = $this->language->get('text_complete'); + + $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete'); + } + + $json['success'] = $this->language->get('text_success'); + } else { + $json['error'] = (isset($response['L_SHORTMESSAGE0']) ? $response['L_SHORTMESSAGE0'] : $this->language->get('error_transaction')); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/pp_express_refund'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'], true), + ); + + //button actions + $data['action'] = $this->url->link('extension/payment/pp_express/doRefund', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + + $data['transaction_id'] = $this->request->get['transaction_id']; + + $this->load->model('extension/payment/pp_express'); + $pp_transaction = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']); + + $data['amount_original'] = $pp_transaction['AMT']; + $data['currency_code'] = $pp_transaction['CURRENCYCODE']; + + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotalByParentId($this->request->get['transaction_id']), 2); + + if ($refunded != 0.00) { + $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2); + $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available']; + } else { + $data['refund_available'] = ''; + $data['attention'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_refund', $data)); + } + + public function doRefund() { + /** + * used to issue a refund for a captured payment + * + * refund can be full or partial + */ + if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) { + + $this->load->model('extension/payment/pp_express'); + $this->load->language('extension/payment/pp_express_refund'); + + if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) { + $this->session->data['error'] = $this->language->get('error_partial_amt'); + } else { + $order_id = $this->model_extension_payment_pp_express->getOrderId($this->request->post['transaction_id']); + $paypal_order = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_order) { + $call_data = array(); + $call_data['METHOD'] = 'RefundTransaction'; + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + $call_data['NOTE'] = urlencode($this->request->post['refund_message']); + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $current_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($this->request->post['transaction_id']); + + if ($this->request->post['refund_full'] == 1) { + $call_data['REFUNDTYPE'] = 'Full'; + } else { + $call_data['REFUNDTYPE'] = 'Partial'; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + $result = $this->model_extension_payment_pp_express->call($call_data); + + $transaction = array( + 'paypal_order_id' => $paypal_order['paypal_order_id'], + 'transaction_id' => '', + 'parent_transaction_id' => $this->request->post['transaction_id'], + 'note' => $this->request->post['refund_message'], + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => 'refund', + 'payment_status' => 'Refunded', + 'transaction_entity' => 'payment', + 'pending_reason' => '', + 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']), + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['payment_status'] = 'Failed'; + $this->model_extension_payment_pp_express->addTransaction($transaction, $call_data); + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + $transaction['pending_reason'] = $result['PENDINGREASON']; + $transaction['amount'] = '-' . $result['GROSSREFUNDAMT']; + + $this->model_extension_payment_pp_express->addTransaction($transaction); + + //edit transaction to refunded status + if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1"); + } else { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1"); + } + + //redirect back to the order + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else { + $this->model_extension_payment_pp_express->log(json_encode($result)); + $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : ''); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } else { + $this->session->data['error'] = $this->language->get('error_data_missing'); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + } else { + $this->session->data['error'] = $this->language->get('error_data'); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + + /** + * used to void an authorised payment + */ + public function void() { + $json = array(); + + $this->load->language('extension/payment/pp_express_order'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + $request = array( + 'METHOD' => 'DoVoid', + 'AUTHORIZATIONID' => $paypal_info['authorization_id'], + 'MSGSUBID' => uniqid(mt_rand(), true) + ); + + $response_info = $this->model_extension_payment_pp_express->call($request); + + if (isset($response_info['ACK']) && ($response_info['ACK'] != 'Failure') && ($response_info['ACK'] != 'FailureWithWarning')) { + $transaction = array( + 'paypal_order_id' => $paypal_info['paypal_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_info['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'void', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'transaction_entity' => 'auth', + 'amount' => '', + 'debug_data' => json_encode($response_info) + ); + + $this->model_extension_payment_pp_express->addTransaction($transaction); + + $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete'); + + $json['capture_status'] = 'Complete'; + + $json['success'] = $this->language->get('text_success'); + } else { + $json['error'] = (isset($response_info['L_SHORTMESSAGE0']) ? $response_info['L_SHORTMESSAGE0'] : $this->language->get('error_transaction')); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + // Cancel an active recurring + public function recurringCancel() { + $json = array(); + + $this->load->language('extension/recurring/pp_express'); + + //cancel an active recurring + $this->load->model('account/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id); + + if ($recurring_info && $recurring_info['reference']) { + if ($this->config->get('payment_pp_express_test')) { + $api_url = 'https://api-3t.sandbox.paypal.com/nvp'; + $api_username = $this->config->get('payment_pp_express_sandbox_username'); + $api_password = $this->config->get('payment_pp_express_sandbox_password'); + $api_signature = $this->config->get('payment_pp_express_sandbox_signature'); + } else { + $api_url = 'https://api-3t.paypal.com/nvp'; + $api_username = $this->config->get('payment_pp_express_username'); + $api_password = $this->config->get('payment_pp_express_password'); + $api_signature = $this->config->get('payment_pp_express_signature'); + } + + $request = array( + 'USER' => $api_username, + 'PWD' => $api_password, + 'SIGNATURE' => $api_signature, + 'VERSION' => '109.0', + 'BUTTONSOURCE' => 'OpenCart_2.0_EC', + 'METHOD' => 'SetExpressCheckout', + 'METHOD' => 'ManageRecurringPaymentsProfileStatus', + 'PROFILEID' => $recurring_info['reference'], + 'ACTION' => 'Cancel' + ); + + $curl = curl_init($api_url); + + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $request); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $response = curl_exec($curl); + + if (!$response) { + $this->log(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl))); + } + + curl_close($curl); + + $response_info = array(); + + parse_str($response, $response_info); + + if (isset($response_info['PROFILEID'])) { + $this->model_account_recurring->editOrderRecurringStatus($order_recurring_id, 4); + $this->model_account_recurring->addOrderRecurringTransaction($order_recurring_id, 5); + + $json['success'] = $this->language->get('text_cancelled'); + } else { + $json['error'] = sprintf($this->language->get('error_not_cancelled'), $response_info['L_LONGMESSAGE0']); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function resend() { + $json = array(); + + $this->load->language('extension/payment/pp_express'); + + if (isset($this->request->get['paypal_order_transaction_id'])) { + $paypal_order_transaction_id = $this->request->get['paypal_order_transaction_id']; + } else { + $paypal_order_transaction_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $transaction = $this->model_extension_payment_pp_express->getFailedTransaction($paypal_order_transaction_id); + + if ($transaction) { + + $call_data = json_decode($transaction['call_data'], true); + + $result = $this->model_extension_payment_pp_express->call($call_data); + + if ($result) { + + $parent_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($transaction['parent_id']); + + if ($parent_transaction['amount'] == abs($transaction['amount'])) { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1"); + } else { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1"); + } + + if (isset($result['REFUNDTRANSACTIONID'])) { + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + } else { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + } + + if (isset($result['PAYMENTTYPE'])) { + $transaction['payment_type'] = $result['PAYMENTTYPE']; + } else { + $transaction['payment_type'] = $result['REFUNDSTATUS']; + } + + if (isset($result['PAYMENTSTATUS'])) { + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + } else { + $transaction['payment_status'] = 'Refunded'; + } + + if (isset($result['AMT'])) { + $transaction['amount'] = $result['AMT']; + } else { + $transaction['amount'] = $transaction['amount']; + } + + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + + $this->model_extension_payment_pp_express->updateTransaction($transaction); + + $json['success'] = $this->language->get('success_transaction_resent'); + } else { + $json['error'] = $this->language->get('error_timeout'); + } + } else { + $json['error'] = $this->language->get('error_transaction_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function search() { + $this->load->language('extension/payment/pp_express_search'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true), + ); + + $this->load->model('extension/payment/pp_express'); + + $data['currency_codes'] = $this->model_extension_payment_pp_express->getCurrencies(); + + $data['default_currency'] = $this->config->get('payment_pp_express_currency'); + + $data['date_start'] = date("Y-m-d", strtotime('-30 days')); + $data['date_end'] = date("Y-m-d"); + $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_search', $data)); + } + + public function info() { + $this->load->language('extension/payment/pp_express_view'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true), + ); + + $this->load->model('extension/payment/pp_express'); + + $data['transaction'] = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']); + $data['lines'] = $this->formatRows($data['transaction']); + $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_view', $data)); + } + + public function doSearch() { + /** + * used to search for transactions from a user account + */ + if (isset($this->request->post['date_start'])) { + + $this->load->model('extension/payment/pp_express'); + + $call_data = array(); + $call_data['METHOD'] = 'TransactionSearch'; + $call_data['STARTDATE'] = gmdate($this->request->post['date_start'] . "\TH:i:s\Z"); + + if (!empty($this->request->post['date_end'])) { + $call_data['ENDDATE'] = gmdate($this->request->post['date_end'] . "\TH:i:s\Z"); + } + + if (!empty($this->request->post['transaction_class'])) { + $call_data['TRANSACTIONCLASS'] = $this->request->post['transaction_class']; + } + + if (!empty($this->request->post['status'])) { + $call_data['STATUS'] = $this->request->post['status']; + } + + if (!empty($this->request->post['buyer_email'])) { + $call_data['EMAIL'] = $this->request->post['buyer_email']; + } + + if (!empty($this->request->post['merchant_email'])) { + $call_data['RECEIVER'] = $this->request->post['merchant_email']; + } + + if (!empty($this->request->post['receipt_id'])) { + $call_data['RECEIPTID'] = $this->request->post['receipt_id']; + } + + if (!empty($this->request->post['transaction_id'])) { + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + } + + if (!empty($this->request->post['invoice_number'])) { + $call_data['INVNUM'] = $this->request->post['invoice_number']; + } + + if (!empty($this->request->post['auction_item_number'])) { + $call_data['AUCTIONITEMNUMBER'] = $this->request->post['auction_item_number']; + } + + if (!empty($this->request->post['amount'])) { + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + if (!empty($this->request->post['recurring_id'])) { + $call_data['PROFILEID'] = $this->request->post['recurring_id']; + } + + if (!empty($this->request->post['name_salutation'])) { + $call_data['SALUTATION'] = $this->request->post['name_salutation']; + } + + if (!empty($this->request->post['name_first'])) { + $call_data['FIRSTNAME'] = $this->request->post['name_first']; + } + + if (!empty($this->request->post['name_middle'])) { + $call_data['MIDDLENAME'] = $this->request->post['name_middle']; + } + + if (!empty($this->request->post['name_last'])) { + $call_data['LASTNAME'] = $this->request->post['name_last']; + } + + if (!empty($this->request->post['name_suffix'])) { + $call_data['SUFFIX'] = $this->request->post['name_suffix']; + } + + $result = $this->model_extension_payment_pp_express->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning' && $result['ACK'] != 'Warning') { + $response['error'] = false; + $response['result'] = $this->formatRows($result); + } else { + $response['error'] = true; + $response['error_msg'] = $result['L_LONGMESSAGE0']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } else { + $response['error'] = true; + $response['error_msg'] = 'Enter a start date'; + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + } + + public function live() { + if (isset($this->request->get['merchantId'])) { + $this->load->language('extension/payment/pp_express'); + + $this->load->model('extension/payment/pp_express'); + $this->load->model('setting/setting'); + + $token = $this->model_extension_payment_pp_express->getTokens('live'); + + if (isset($token->access_token)) { + $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'live', $token->access_token); + } else { + $this->session->data['error_api'] = $this->language->get('error_api'); + } + + if (isset($user_info->api_user_name)) { + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_username', $user_info->api_user_name); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_password', $user_info->api_password); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_signature', $user_info->signature); + } else { + $this->session->data['error_api'] = $this->language->get('error_api'); + } + } + + $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function sandbox() { + if (isset($this->request->get['merchantId'])) { + $this->load->language('extension/payment/pp_express'); + + $this->load->model('extension/payment/pp_express'); + $this->load->model('setting/setting'); + + $token = $this->model_extension_payment_pp_express->getTokens('sandbox'); + + if (isset($token->access_token)) { + $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'sandbox', $token->access_token); + } else { + $this->session->data['error_api'] = $this->language->get('error_api_sandbox'); + } + + if (isset($user_info->api_user_name)) { + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_username', $user_info->api_user_name); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_password', $user_info->api_password); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_signature', $user_info->signature); + } else { + $this->session->data['error_api'] = $this->language->get('error_api_sandbox'); + } + } + $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true)); + } + + private function formatRows($data) { + $return = array(); + + foreach ($data as $k => $v) { + $elements = preg_split("/(\d+)/", $k, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + if (isset($elements[1]) && isset($elements[0])) { + if ($elements[0] == 'L_TIMESTAMP') { + $v = str_replace('T', ' ', $v); + $v = str_replace('Z', '', $v); + } + $return[$elements[1]][$elements[0]] = $v; + } + } + + return $return; + } + + public function recurringButtons() { + $this->load->model('sale/recurring'); + + $recurring = $this->model_sale_recurring->getRecurring($this->request->get['order_recurring_id']); + + $data['buttons'] = array(); + + if ($recurring['status'] == 2 || $recurring['status'] == 3) { + $data['buttons'][] = array( + 'text' => $this->language->get('button_cancel_recurring'), + 'link' => $this->url->link('extension/payment/pp_express/recurringCancel', 'order_recurring_id=' . $this->request->get['order_recurring_id'] . '&user_token=' . $this->request->get['user_token'], true) + ); + } + + return $this->load->view('sale/recurring_button', $data); + } + + public function connectRedirect() { + if ($this->user->hasPermission('modify', 'extension/extension/payment') && $this->user->hasPermission('modify', 'extension/payment/pp_express')) { + // Install the module before doing the redirect + $this->load->model('setting/extension'); + + $this->model_setting_extension->install('payment', 'pp_express'); + + $this->install(); + + $this->load->model('localisation/country'); + + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + // Create Live link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'live'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $this->response->redirect($curl_response['url']); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function promotion() { + $this->load->language('extension/payment/pp_express'); + + $data['connect_link'] = ''; + $data['module_link'] = ''; + + if ($this->config->get('payment_pp_express_username') || $this->config->get('payment_pp_express_sandbox_username')) { + $data['module_link'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + } else { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + $data['connect_link'] = $this->url->link('extension/payment/pp_express/connectRedirect', 'user_token=' . $this->session->data['user_token'], true); + } + } + + if ($this->config->get("payment_pp_express_status") == 1) { + $data['payment_pp_express_status'] = "enabled"; + } elseif ($this->config->get("payment_pp_express_status") == null) { + $data['payment_pp_express_status'] = ""; + } else { + $data['payment_pp_express_status'] = "disabled"; + } + + return $this->load->view('extension/payment/pp_express_promotion', $data); + } +} diff --git a/public/admin/controller/extension/payment/pp_payflow.php b/public/admin/controller/extension/payment/pp_payflow.php new file mode 100644 index 0000000..92ca1a0 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_payflow.php @@ -0,0 +1,177 @@ +<?php +class ControllerExtensionPaymentPPPayflow extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_payflow'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_payflow', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + if (isset($this->error['user'])) { + $data['error_user'] = $this->error['user']; + } else { + $data['error_user'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['partner'])) { + $data['error_partner'] = $this->error['partner']; + } else { + $data['error_partner'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_payflow', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_payflow_vendor'])) { + $data['payment_pp_payflow_vendor'] = $this->request->post['payment_pp_payflow_vendor']; + } else { + $data['payment_pp_payflow_vendor'] = $this->config->get('payment_pp_payflow_vendor'); + } + + if (isset($this->request->post['payment_pp_payflow_user'])) { + $data['payment_pp_payflow_user'] = $this->request->post['payment_pp_payflow_user']; + } else { + $data['payment_pp_payflow_user'] = $this->config->get('payment_pp_payflow_user'); + } + + if (isset($this->request->post['payment_pp_payflow_password'])) { + $data['payment_pp_payflow_password'] = $this->request->post['payment_pp_payflow_password']; + } else { + $data['payment_pp_payflow_password'] = $this->config->get('payment_pp_payflow_password'); + } + + if (isset($this->request->post['payment_pp_payflow_partner'])) { + $data['payment_pp_payflow_partner'] = $this->request->post['payment_pp_payflow_partner']; + } elseif ($this->config->has('payment_pp_payflow_partner')) { + $data['payment_pp_payflow_partner'] = $this->config->get('payment_pp_payflow_partner'); + } else { + $data['payment_pp_payflow_partner'] = 'PayPal'; + } + + if (isset($this->request->post['payment_pp_payflow_test'])) { + $data['payment_pp_payflow_test'] = $this->request->post['payment_pp_payflow_test']; + } else { + $data['payment_pp_payflow_test'] = $this->config->get('payment_pp_payflow_test'); + } + + if (isset($this->request->post['payment_pp_payflow_transaction'])) { + $data['payment_pp_payflow_transaction'] = $this->request->post['payment_pp_payflow_transaction']; + } else { + $data['payment_pp_payflow_transaction'] = $this->config->get('payment_pp_payflow_transaction'); + } + + if (isset($this->request->post['payment_pp_payflow_total'])) { + $data['payment_pp_payflow_total'] = $this->request->post['payment_pp_payflow_total']; + } else { + $data['payment_pp_payflow_total'] = $this->config->get('payment_pp_payflow_total'); + } + + if (isset($this->request->post['payment_pp_payflow_order_status_id'])) { + $data['payment_pp_payflow_order_status_id'] = $this->request->post['payment_pp_payflow_order_status_id']; + } else { + $data['payment_pp_payflow_order_status_id'] = $this->config->get('payment_pp_payflow_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_payflow_geo_zone_id'])) { + $data['payment_pp_payflow_geo_zone_id'] = $this->request->post['payment_pp_payflow_geo_zone_id']; + } else { + $data['payment_pp_payflow_geo_zone_id'] = $this->config->get('payment_pp_payflow_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_payflow_status'])) { + $data['payment_pp_payflow_status'] = $this->request->post['payment_pp_payflow_status']; + } else { + $data['payment_pp_payflow_status'] = $this->config->get('payment_pp_payflow_status'); + } + + if (isset($this->request->post['payment_pp_payflow_sort_order'])) { + $data['payment_pp_payflow_sort_order'] = $this->request->post['payment_pp_payflow_sort_order']; + } else { + $data['payment_pp_payflow_sort_order'] = $this->config->get('payment_pp_payflow_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_payflow_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + if (!$this->request->post['payment_pp_payflow_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_payflow_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_payflow_partner']) { + $this->error['partner'] = $this->language->get('error_partner'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_payflow_iframe.php b/public/admin/controller/extension/payment/pp_payflow_iframe.php new file mode 100644 index 0000000..635751a --- /dev/null +++ b/public/admin/controller/extension/payment/pp_payflow_iframe.php @@ -0,0 +1,483 @@ +<?php +class ControllerExtensionPaymentPPPayflowIframe extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_payflow_iframe'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_payflow_iframe', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + if (isset($this->error['user'])) { + $data['error_user'] = $this->error['user']; + } else { + $data['error_user'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['partner'])) { + $data['error_partner'] = $this->error['partner']; + } else { + $data['error_partner'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_payflow_iframe_vendor'])) { + $data['payment_pp_payflow_iframe_vendor'] = $this->request->post['payment_pp_payflow_iframe_vendor']; + } else { + $data['payment_pp_payflow_iframe_vendor'] = $this->config->get('payment_pp_payflow_iframe_vendor'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_user'])) { + $data['payment_pp_payflow_iframe_user'] = $this->request->post['payment_pp_payflow_iframe_user']; + } else { + $data['payment_pp_payflow_iframe_user'] = $this->config->get('payment_pp_payflow_iframe_user'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_password'])) { + $data['payment_pp_payflow_iframe_password'] = $this->request->post['payment_pp_payflow_iframe_password']; + } else { + $data['payment_pp_payflow_iframe_password'] = $this->config->get('payment_pp_payflow_iframe_password'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_partner'])) { + $data['payment_pp_payflow_iframe_partner'] = $this->request->post['payment_pp_payflow_iframe_partner']; + } else { + $data['payment_pp_payflow_iframe_partner'] = $this->config->get('payment_pp_payflow_iframe_partner'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_transaction_method'])) { + $data['payment_pp_payflow_iframe_transaction_method'] = $this->request->post['payment_pp_payflow_iframe_transaction_method']; + } else { + $data['payment_pp_payflow_iframe_transaction_method'] = $this->config->get('payment_pp_payflow_iframe_transaction_method'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_test'])) { + $data['payment_pp_payflow_iframe_test'] = $this->request->post['payment_pp_payflow_iframe_test']; + } else { + $data['payment_pp_payflow_iframe_test'] = $this->config->get('payment_pp_payflow_iframe_test'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_total'])) { + $data['payment_pp_payflow_iframe_total'] = $this->request->post['payment_pp_payflow_iframe_total']; + } else { + $data['payment_pp_payflow_iframe_total'] = $this->config->get('payment_pp_payflow_iframe_total'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_payflow_iframe_order_status_id'])) { + $data['payment_pp_payflow_iframe_order_status_id'] = $this->request->post['payment_pp_payflow_iframe_order_status_id']; + } else { + $data['payment_pp_payflow_iframe_order_status_id'] = $this->config->get('payment_pp_payflow_iframe_order_status_id'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_geo_zone_id'])) { + $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->request->post['payment_pp_payflow_iframe_geo_zone_id']; + } else { + $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->config->get('payment_pp_payflow_iframe_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_payflow_iframe_status'])) { + $data['payment_pp_payflow_iframe_status'] = $this->request->post['payment_pp_payflow_iframe_status']; + } else { + $data['payment_pp_payflow_iframe_status'] = $this->config->get('payment_pp_payflow_iframe_status'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_sort_order'])) { + $data['payment_pp_payflow_iframe_sort_order'] = $this->request->post['payment_pp_payflow_iframe_sort_order']; + } else { + $data['payment_pp_payflow_iframe_sort_order'] = $this->config->get('payment_pp_payflow_iframe_sort_order'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_checkout_method'])) { + $data['payment_pp_payflow_iframe_checkout_method'] = $this->request->post['payment_pp_payflow_iframe_checkout_method']; + } else { + $data['payment_pp_payflow_iframe_checkout_method'] = $this->config->get('payment_pp_payflow_iframe_checkout_method'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_debug'])) { + $data['payment_pp_payflow_iframe_debug'] = $this->request->post['payment_pp_payflow_iframe_debug']; + } else { + $data['payment_pp_payflow_iframe_debug'] = $this->config->get('payment_pp_payflow_iframe_debug'); + } + + $data['post_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentipn'; + $data['cancel_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentcancel'; + $data['error_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymenterror'; + $data['return_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentreturn'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow_iframe', $data)); + } + + public function install() { + $this->load->model('extension/payment/pp_payflow_iframe'); + + $this->model_extension_payment_pp_payflow_iframe->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_payflow_iframe'); + + $this->model_extension_payment_pp_payflow_iframe->uninstall(); + } + + public function refund() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->model('sale/order'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->get['transaction_reference']); + + if ($transaction) { + $this->document->setTitle($this->language->get('heading_refund')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $this->request->get['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true) + ); + + $data['transaction_reference'] = $transaction['transaction_reference']; + $data['transaction_amount'] = number_format($transaction['amount'], 2); + $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow_iframe_refund', $data)); + } else { + return $this->forward('error/not_found'); + } + } + + public function doRefund() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + $json = array(); + + if (isset($this->request->post['transaction_reference']) && isset($this->request->post['amount'])) { + + $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->post['transaction_reference']); + + if ($transaction) { + $call_data = array( + 'TRXTYPE' => 'C', + 'TENDER' => 'C', + 'ORIGID' => $transaction['transaction_reference'], + 'AMT' => $this->request->post['amount'], + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + $json['success'] = $this->language->get('text_refund_issued'); + + $data = array( + 'order_id' => $transaction['order_id'], + 'type' => 'C', + 'transaction_reference' => $result['PNREF'], + 'amount' => $this->request->post['amount'], + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->model('sale/order'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + if (isset($this->request->post['order_id']) && isset($this->request->post['amount']) && isset($this->request->post['complete'])) { + $order_id = $this->request->post['order_id']; + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + $paypal_transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id); + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($paypal_order && $order_info) { + if ($this->request->post['complete'] == 1) { + $complete = 'Y'; + } else { + $complete = 'N'; + } + + $call_data = array( + 'TRXTYPE' => 'D', + 'TENDER' => 'C', + 'ORIGID' => $paypal_order['transaction_reference'], + 'AMT' => $this->request->post['amount'], + 'CAPTURECOMPLETE' => $complete + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + + $data = array( + 'order_id' => $order_id, + 'type' => 'D', + 'transaction_reference' => $result['PNREF'], + 'amount' => $this->request->post['amount'] + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, $this->request->post['complete']); + + $actions = array(); + + $actions[] = array( + 'title' => $this->language->get('text_capture'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $result['PNREF'] . '&user_token=' . $this->session->data['user_token'], true), + ); + + $json['success'] = array( + 'transaction_type' => $this->language->get('text_capture'), + 'transaction_reference' => $result['PNREF'], + 'time' => date('Y-m-d H:i:s'), + 'amount' => number_format($this->request->post['amount'], 2), + 'actions' => $actions, + ); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $order_id = $this->request->post['order_id']; + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + + if ($paypal_order) { + $call_data = array( + 'TRXTYPE' => 'V', + 'TENDER' => 'C', + 'ORIGID' => $paypal_order['transaction_reference'], + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + $json['success'] = $this->language->get('text_void_success'); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1); + + $data = array( + 'order_id' => $order_id, + 'type' => 'V', + 'transaction_reference' => $result['PNREF'], + 'amount' => '', + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1); + + $json['success'] = array( + 'transaction_type' => $this->language->get('text_void'), + 'transaction_reference' => $result['PNREF'], + 'time' => date('Y-m-d H:i:s'), + 'amount' => '0.00', + ); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + $order_id = $this->request->get['order_id']; + + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + + if ($paypal_order) { + $data['complete'] = $paypal_order['complete']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + $data['transactions'] = array(); + + $transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id); + + foreach ($transactions as $transaction) { + $actions = array(); + + switch ($transaction['transaction_type']) { + case 'V': + $transaction_type = $this->language->get('text_void'); + break; + case 'S': + $transaction_type = $this->language->get('text_sale'); + + $actions[] = array( + 'title' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true), + ); + break; + case 'D': + $transaction_type = $this->language->get('text_capture'); + + $actions[] = array( + 'title' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true), + ); + break; + case 'A': + $transaction_type = $this->language->get('text_authorise'); + break; + + case 'C': + $transaction_type = $this->language->get('text_refund');# + break; + + default: + $transaction_type = ''; + break; + } + + $data['transactions'][] = array( + 'transaction_reference' => $transaction['transaction_reference'], + 'transaction_type' => $transaction_type, + 'time' => $transaction['time'], + 'amount' => $transaction['amount'], + 'actions' => $actions + ); + } + + return $this->load->view('extension/payment/pp_payflow_iframe_order', $data); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow_iframe')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_partner']) { + $this->error['partner'] = $this->language->get('error_partner'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/pp_pro.php b/public/admin/controller/extension/payment/pp_pro.php new file mode 100644 index 0000000..77ab2d7 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_pro.php @@ -0,0 +1,159 @@ +<?php +class ControllerExtensionPaymentPPPro extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_pro'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_pro', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_pro', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_pro_username'])) { + $data['payment_pp_pro_username'] = $this->request->post['payment_pp_pro_username']; + } else { + $data['payment_pp_pro_username'] = $this->config->get('payment_pp_pro_username'); + } + + if (isset($this->request->post['payment_pp_pro_password'])) { + $data['payment_pp_pro_password'] = $this->request->post['payment_pp_pro_password']; + } else { + $data['payment_pp_pro_password'] = $this->config->get('payment_pp_pro_password'); + } + + if (isset($this->request->post['payment_pp_pro_signature'])) { + $data['payment_pp_pro_signature'] = $this->request->post['payment_pp_pro_signature']; + } else { + $data['payment_pp_pro_signature'] = $this->config->get('payment_pp_pro_signature'); + } + + if (isset($this->request->post['payment_pp_pro_test'])) { + $data['payment_pp_pro_test'] = $this->request->post['payment_pp_pro_test']; + } else { + $data['payment_pp_pro_test'] = $this->config->get('payment_pp_pro_test'); + } + + if (isset($this->request->post['payment_pp_pro_transaction'])) { + $data['payment_pp_pro_transaction'] = $this->request->post['payment_pp_pro_transaction']; + } else { + $data['payment_pp_pro_transaction'] = $this->config->get('payment_pp_pro_transaction'); + } + + if (isset($this->request->post['payment_pp_pro_total'])) { + $data['payment_pp_pro_total'] = $this->request->post['payment_pp_pro_total']; + } else { + $data['payment_pp_pro_total'] = $this->config->get('payment_pp_pro_total'); + } + + if (isset($this->request->post['payment_pp_pro_order_status_id'])) { + $data['payment_pp_pro_order_status_id'] = $this->request->post['payment_pp_pro_order_status_id']; + } else { + $data['payment_pp_pro_order_status_id'] = $this->config->get('payment_pp_pro_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_pro_geo_zone_id'])) { + $data['payment_pp_pro_geo_zone_id'] = $this->request->post['payment_pp_pro_geo_zone_id']; + } else { + $data['payment_pp_pro_geo_zone_id'] = $this->config->get('payment_pp_pro_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_pro_status'])) { + $data['payment_pp_pro_status'] = $this->request->post['payment_pp_pro_status']; + } else { + $data['payment_pp_pro_status'] = $this->config->get('payment_pp_pro_status'); + } + + if (isset($this->request->post['payment_pp_pro_sort_order'])) { + $data['payment_pp_pro_sort_order'] = $this->request->post['payment_pp_pro_sort_order']; + } else { + $data['payment_pp_pro_sort_order'] = $this->config->get('payment_pp_pro_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_pro_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_pp_pro_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_pro_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_pro_iframe.php b/public/admin/controller/extension/payment/pp_pro_iframe.php new file mode 100644 index 0000000..489b017 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_pro_iframe.php @@ -0,0 +1,771 @@ +<?php +class ControllerExtensionPaymentPPProIframe extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_pro_iframe'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_pro_iframe', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } else { + $data['error'] = @$this->error; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_pro_iframe_sig'])) { + $data['payment_pp_pro_iframe_sig'] = $this->request->post['payment_pp_pro_iframe_sig']; + } else { + $data['payment_pp_pro_iframe_sig'] = $this->config->get('payment_pp_pro_iframe_sig'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_user'])) { + $data['payment_pp_pro_iframe_user'] = $this->request->post['payment_pp_pro_iframe_user']; + } else { + $data['payment_pp_pro_iframe_user'] = $this->config->get('payment_pp_pro_iframe_user'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_password'])) { + $data['payment_pp_pro_iframe_password'] = $this->request->post['payment_pp_pro_iframe_password']; + } else { + $data['payment_pp_pro_iframe_password'] = $this->config->get('payment_pp_pro_iframe_password'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_transaction_method'])) { + $data['payment_pp_pro_iframe_transaction_method'] = $this->request->post['payment_pp_pro_iframe_transaction_method']; + } else { + $data['payment_pp_pro_iframe_transaction_method'] = $this->config->get('payment_pp_pro_iframe_transaction_method'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_test'])) { + $data['payment_pp_pro_iframe_test'] = $this->request->post['payment_pp_pro_iframe_test']; + } else { + $data['payment_pp_pro_iframe_test'] = $this->config->get('payment_pp_pro_iframe_test'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_total'])) { + $data['payment_pp_pro_iframe_total'] = $this->request->post['payment_pp_pro_iframe_total']; + } else { + $data['payment_pp_pro_iframe_total'] = $this->config->get('payment_pp_pro_iframe_total'); + } + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id'])) { + $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id']; + } else { + $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->config->get('payment_pp_pro_iframe_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_completed_status_id'])) { + $data['payment_pp_pro_iframe_completed_status_id'] = $this->request->post['payment_pp_pro_iframe_completed_status_id']; + } else { + $data['payment_pp_pro_iframe_completed_status_id'] = $this->config->get('payment_pp_pro_iframe_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_denied_status_id'])) { + $data['payment_pp_pro_iframe_denied_status_id'] = $this->request->post['payment_pp_pro_iframe_denied_status_id']; + } else { + $data['payment_pp_pro_iframe_denied_status_id'] = $this->config->get('payment_pp_pro_iframe_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_expired_status_id'])) { + $data['payment_pp_pro_iframe_expired_status_id'] = $this->request->post['payment_pp_pro_iframe_expired_status_id']; + } else { + $data['payment_pp_pro_iframe_expired_status_id'] = $this->config->get('payment_pp_pro_iframe_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_failed_status_id'])) { + $data['payment_pp_pro_iframe_failed_status_id'] = $this->request->post['payment_pp_pro_iframe_failed_status_id']; + } else { + $data['payment_pp_pro_iframe_failed_status_id'] = $this->config->get('payment_pp_pro_iframe_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_pending_status_id'])) { + $data['payment_pp_pro_iframe_pending_status_id'] = $this->request->post['payment_pp_pro_iframe_pending_status_id']; + } else { + $data['payment_pp_pro_iframe_pending_status_id'] = $this->config->get('payment_pp_pro_iframe_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id']; + } else { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id']; + } else { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_reversed_status_id'])) { + $data['payment_pp_pro_iframe_reversed_status_id'] = $this->request->post['payment_pp_pro_iframe_reversed_status_id']; + } else { + $data['payment_pp_pro_iframe_reversed_status_id'] = $this->config->get('payment_pp_pro_iframe_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_voided_status_id'])) { + $data['payment_pp_pro_iframe_voided_status_id'] = $this->request->post['payment_pp_pro_iframe_voided_status_id']; + } else { + $data['payment_pp_pro_iframe_voided_status_id'] = $this->config->get('payment_pp_pro_iframe_voided_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_geo_zone_id'])) { + $data['payment_pp_pro_iframe_geo_zone_id'] = $this->request->post['payment_pp_pro_iframe_geo_zone_id']; + } else { + $data['payment_pp_pro_iframe_geo_zone_id'] = $this->config->get('payment_pp_pro_iframe_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_pro_iframe_status'])) { + $data['payment_pp_pro_iframe_status'] = $this->request->post['payment_pp_pro_iframe_status']; + } else { + $data['payment_pp_pro_iframe_status'] = $this->config->get('payment_pp_pro_iframe_status'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_sort_order'])) { + $data['payment_pp_pro_iframe_sort_order'] = $this->request->post['payment_pp_pro_iframe_sort_order']; + } else { + $data['payment_pp_pro_iframe_sort_order'] = $this->config->get('payment_pp_pro_iframe_sort_order'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_checkout_method'])) { + $data['payment_pp_pro_iframe_checkout_method'] = $this->request->post['payment_pp_pro_iframe_checkout_method']; + } else { + $data['payment_pp_pro_iframe_checkout_method'] = $this->config->get('payment_pp_pro_iframe_checkout_method'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_debug'])) { + $data['payment_pp_pro_iframe_debug'] = $this->request->post['payment_pp_pro_iframe_debug']; + } else { + $data['payment_pp_pro_iframe_debug'] = $this->config->get('payment_pp_pro_iframe_debug'); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_pro_iframe/notify'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe', $data)); + } + + public function install() { + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->model_extension_payment_pp_pro_iframe->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->model_extension_payment_pp_pro_iframe->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro_iframe')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_pro_iframe_sig']) { + $this->error['sig'] = $this->language->get('error_sig'); + } + + if (!$this->request->post['payment_pp_pro_iframe_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_pro_iframe_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + return !$this->error; + } + + public function order() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->get['order_id']); + + if ($paypal_order) { + $data['paypal_order'] = $paypal_order; + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($data['paypal_order']['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($data['paypal_order']['paypal_iframe_order_id']), 2); + + $data['paypal_order']['captured'] = $captured; + $data['paypal_order']['refunded'] = $refunded; + $data['paypal_order']['remaining'] = number_format($data['paypal_order']['total'] - $captured, 2); + + $data['transactions'] = array(); + + $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true); + $data['refund_link'] = $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true); + $data['resend_link'] = $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'], true); + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2); + + $data['paypal_order'] = $paypal_order; + + $data['paypal_order']['captured'] = $captured; + $data['paypal_order']['refunded'] = $refunded; + $data['paypal_order']['remaining'] = number_format($paypal_order['total'] - $captured, 2); + + foreach ($paypal_order['transactions'] as $transaction) { + $data['transactions'][] = array( + 'paypal_iframe_order_transaction_id' => $transaction['paypal_iframe_order_transaction_id'], + 'transaction_id' => $transaction['transaction_id'], + 'amount' => $transaction['amount'], + 'date_added' => $transaction['date_added'], + 'payment_type' => $transaction['payment_type'], + 'payment_status' => $transaction['payment_status'], + 'pending_reason' => $transaction['pending_reason'], + 'view' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . '&order_id=' . $this->request->get['order_id'], true), + 'refund' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . "&order_id=" . $this->request->get['order_id'], true), + 'resend' => $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'] . "&paypal_iframe_order_transaction_id=" . $transaction['paypal_iframe_order_transaction_id'], true), + ); + } + + $data['reauthorise_link'] = $this->url->link('extension/payment/pp_pro_iframe/reauthorise', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/payment/pp_pro_iframe_order', $data); + } + } + + public function refund() { + $this->load->language('extension/payment/pp_pro_iframe'); + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->document->setTitle($this->language->get('text_refund')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true) + ); + + //button actions + $data['action'] = $this->url->link('extension/payment/pp_pro_iframe/doRefund', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->get['order_id'])) { + $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + } else { + $data['cancel'] = ''; + } + + $data['transaction_id'] = $this->request->get['transaction_id']; + + $pp_transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']); + + $data['amount_original'] = $pp_transaction['AMT']; + $data['currency_code'] = $pp_transaction['CURRENCYCODE']; + + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefundedTransaction($this->request->get['transaction_id']), 2); + + if ($refunded != 0.00) { + $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2); + $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available']; + } else { + $data['refund_available'] = ''; + $data['attention'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe_refund', $data)); + } + + public function doRefund() { + /** + * used to issue a refund for a captured payment + * + * refund can be full or partial + */ + if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) { + + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) { + $this->session->data['error'] = $this->language->get('error_capture'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } else { + $order_id = $this->model_extension_payment_pp_pro_iframe->getOrderId($this->request->post['transaction_id']); + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($order_id); + + if ($paypal_order) { + $call_data = array(); + $call_data['METHOD'] = 'RefundTransaction'; + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + $call_data['NOTE'] = urlencode($this->request->post['refund_message']); + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $current_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($this->request->post['transaction_id']); + + if ($this->request->post['refund_full'] == 1) { + $call_data['REFUNDTYPE'] = 'Full'; + } else { + $call_data['REFUNDTYPE'] = 'Partial'; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $this->request->post['transaction_id'], + 'note' => $this->request->post['refund_message'], + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => 'Refunded', + 'transaction_entity' => 'payment', + 'pending_reason' => '', + 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']), + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['payment_status'] = 'Failed'; + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data); + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + $transaction['payment_type'] = $result['REFUNDSTATUS']; + $transaction['pending_reason'] = $result['PENDINGREASON']; + $transaction['amount'] = '-' . $result['GROSSREFUNDAMT']; + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Refunded'); + } else { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Partially-Refunded'); + } + + //redirect back to the order + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else { + if ($this->config->get('payment_pp_pro_iframe_debug')) { + $log = new Log('pp_pro_iframe.log'); + $log->write(json_encode($result)); + } + + $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : ''); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } else { + $this->session->data['error'] = $this->language->get('error_data_missing'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + } else { + $this->session->data['error'] = $this->language->get('error_data'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + + public function reauthorise() { + $this->load->language('extension/payment/pp_pro_iframe'); + $this->load->model('extension/payment/pp_pro_iframe'); + + $json = array(); + + if (isset($this->request->post['order_id'])) { + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + $call_data = array(); + $call_data['METHOD'] = 'DoReauthorization'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + $call_data['AMT'] = number_format($paypal_order['total'], 2); + $call_data['CURRENCYCODE'] = $paypal_order['currency_code']; + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $this->model_extension_payment_pp_pro_iframe->updateAuthorizationId($paypal_order['paypal_iframe_order_id'], $result['AUTHORIZATIONID']); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'instant', + 'payment_status' => $result['PAYMENTSTATUS'], + 'transaction_entity' => 'auth', + 'pending_reason' => $result['PENDINGREASON'], + 'amount' => '-' . '', + 'debug_data' => json_encode($result) + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Ok'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general')); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function info() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_transaction'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true) + ); + + $transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']); + $transaction = array_map('urldecode', $transaction); + + $data['transaction'] = $transaction; + $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $this->document->setTitle($this->language->get('text_transaction')); + + if (isset($this->request->get['order_id'])) { + $data['back'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + } else { + $data['back'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe_transaction', $data)); + } + + public function capture() { + $this->load->language('extension/payment/pp_pro_iframe'); + /* + * used to capture authorised payments + * capture can be full or partial amounts + */ + if (isset($this->request->post['order_id']) && $this->request->post['amount'] > 0 && isset($this->request->post['order_id']) && isset($this->request->post['complete'])) { + + $this->load->model('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + if ($this->request->post['complete'] == 1) { + $complete = 'Complete'; + } else { + $complete = 'NotComplete'; + } + + $call_data = array(); + $call_data['METHOD'] = 'DoCapture'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $paypal_order['currency_code']; + $call_data['COMPLETETYPE'] = $complete; + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => '', + 'pending_reason' => '', + 'transaction_entity' => 'payment', + 'amount' => '', + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['amount'] = number_format($this->request->post['amount'], 2); + $paypal_iframe_order_transaction_id = $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data); + + $json['error'] = true; + + $json['failed_transaction']['paypal_iframe_order_transaction_id'] = $paypal_iframe_order_transaction_id; + $json['failed_transaction']['amount'] = $transaction['amount']; + $json['failed_transaction']['date_added'] = date("Y-m-d H:i:s"); + + $json['msg'] = $this->language->get('error_timeout'); + } else if (isset($result['ACK']) && $result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + $transaction['payment_type'] = $result['PAYMENTTYPE']; + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + $transaction['amount'] = $result['AMT']; + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + unset($transaction['debug_data']); + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2); + + $transaction['captured'] = $captured; + $transaction['refunded'] = $refunded; + $transaction['remaining'] = number_format($paypal_order['total'] - $captured, 2); + + $transaction['status'] = 0; + if ($transaction['remaining'] == 0.00) { + $transaction['status'] = 1; + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + } + + $transaction['void'] = ''; + + if ($this->request->post['complete'] == 1 && $transaction['remaining'] > 0) { + $transaction['void'] = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'amount' => '', + 'debug_data' => 'Voided after capture', + 'transaction_entity' => 'auth', + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction['void']); + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + $transaction['void']['date_added'] = date("Y-m-d H:i:s"); + $transaction['status'] = 1; + } + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Ok'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->language('extension/payment/pp_pro_iframe'); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + $call_data = array(); + $call_data['METHOD'] = 'DoVoid'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'void', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'transaction_entity' => 'auth', + 'amount' => '', + 'debug_data' => json_encode($result) + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + + unset($transaction['debug_data']); + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Transaction void'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general')); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function resend() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $json = array(); + + if (isset($this->request->get['paypal_iframe_order_transaction_id'])) { + $transaction = $this->model_extension_payment_pp_pro_iframe->getFailedTransaction($this->request->get['paypal_iframe_order_transaction_id']); + + if ($transaction) { + $call_data = json_decode($transaction['call_data'], true); + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result) { + $parent_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($transaction['parent_id']); + + if ($parent_transaction['amount'] == abs($transaction['amount'])) { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Refunded'); + } else { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Partially-Refunded'); + } + + if (isset($result['REFUNDTRANSACTIONID'])) { + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + } else { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + } + + if (isset($result['PAYMENTTYPE'])) { + $transaction['payment_type'] = $result['PAYMENTTYPE']; + } else { + $transaction['payment_type'] = $result['REFUNDSTATUS']; + } + + if (isset($result['PAYMENTSTATUS'])) { + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + } else { + $transaction['payment_status'] = 'Refunded'; + } + + if (isset($result['AMT'])) { + $transaction['amount'] = $result['AMT']; + } else { + $transaction['amount'] = $transaction['amount']; + } + + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + + $this->model_extension_payment_pp_pro_iframe->updateTransaction($transaction); + + $json['success'] = $this->language->get('success_transaction_resent'); + } else { + $json['error'] = $this->language->get('error_timeout'); + } + } else { + $json['error'] = $this->language->get('error_transaction_missing'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_standard.php b/public/admin/controller/extension/payment/pp_standard.php new file mode 100644 index 0000000..ba9acd8 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_standard.php @@ -0,0 +1,187 @@ +<?php +class ControllerExtensionPaymentPPStandard extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_standard'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_standard', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_standard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_standard', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_standard_email'])) { + $data['payment_pp_standard_email'] = $this->request->post['payment_pp_standard_email']; + } else { + $data['payment_pp_standard_email'] = $this->config->get('payment_pp_standard_email'); + } + + if (isset($this->request->post['payment_pp_standard_test'])) { + $data['payment_pp_standard_test'] = $this->request->post['payment_pp_standard_test']; + } else { + $data['payment_pp_standard_test'] = $this->config->get('payment_pp_standard_test'); + } + + if (isset($this->request->post['payment_pp_standard_transaction'])) { + $data['payment_pp_standard_transaction'] = $this->request->post['payment_pp_standard_transaction']; + } else { + $data['payment_pp_standard_transaction'] = $this->config->get('payment_pp_standard_transaction'); + } + + if (isset($this->request->post['payment_pp_standard_debug'])) { + $data['payment_pp_standard_debug'] = $this->request->post['payment_pp_standard_debug']; + } else { + $data['payment_pp_standard_debug'] = $this->config->get('payment_pp_standard_debug'); + } + + if (isset($this->request->post['payment_pp_standard_total'])) { + $data['payment_pp_standard_total'] = $this->request->post['payment_pp_standard_total']; + } else { + $data['payment_pp_standard_total'] = $this->config->get('payment_pp_standard_total'); + } + + if (isset($this->request->post['payment_pp_standard_canceled_reversal_status_id'])) { + $data['payment_pp_standard_canceled_reversal_status_id'] = $this->request->post['payment_pp_standard_canceled_reversal_status_id']; + } else { + $data['payment_pp_standard_canceled_reversal_status_id'] = $this->config->get('payment_pp_standard_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_completed_status_id'])) { + $data['payment_pp_standard_completed_status_id'] = $this->request->post['payment_pp_standard_completed_status_id']; + } else { + $data['payment_pp_standard_completed_status_id'] = $this->config->get('payment_pp_standard_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_denied_status_id'])) { + $data['payment_pp_standard_denied_status_id'] = $this->request->post['payment_pp_standard_denied_status_id']; + } else { + $data['payment_pp_standard_denied_status_id'] = $this->config->get('payment_pp_standard_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_expired_status_id'])) { + $data['payment_pp_standard_expired_status_id'] = $this->request->post['payment_pp_standard_expired_status_id']; + } else { + $data['payment_pp_standard_expired_status_id'] = $this->config->get('payment_pp_standard_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_failed_status_id'])) { + $data['payment_pp_standard_failed_status_id'] = $this->request->post['payment_pp_standard_failed_status_id']; + } else { + $data['payment_pp_standard_failed_status_id'] = $this->config->get('payment_pp_standard_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_pending_status_id'])) { + $data['payment_pp_standard_pending_status_id'] = $this->request->post['payment_pp_standard_pending_status_id']; + } else { + $data['payment_pp_standard_pending_status_id'] = $this->config->get('payment_pp_standard_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_processed_status_id'])) { + $data['payment_pp_standard_processed_status_id'] = $this->request->post['payment_pp_standard_processed_status_id']; + } else { + $data['payment_pp_standard_processed_status_id'] = $this->config->get('payment_pp_standard_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_refunded_status_id'])) { + $data['payment_pp_standard_refunded_status_id'] = $this->request->post['payment_pp_standard_refunded_status_id']; + } else { + $data['payment_pp_standard_refunded_status_id'] = $this->config->get('payment_pp_standard_refunded_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_reversed_status_id'])) { + $data['payment_pp_standard_reversed_status_id'] = $this->request->post['payment_pp_standard_reversed_status_id']; + } else { + $data['payment_pp_standard_reversed_status_id'] = $this->config->get('payment_pp_standard_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_voided_status_id'])) { + $data['payment_pp_standard_voided_status_id'] = $this->request->post['payment_pp_standard_voided_status_id']; + } else { + $data['payment_pp_standard_voided_status_id'] = $this->config->get('payment_pp_standard_voided_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_standard_geo_zone_id'])) { + $data['payment_pp_standard_geo_zone_id'] = $this->request->post['payment_pp_standard_geo_zone_id']; + } else { + $data['payment_pp_standard_geo_zone_id'] = $this->config->get('payment_pp_standard_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_standard_status'])) { + $data['payment_pp_standard_status'] = $this->request->post['payment_pp_standard_status']; + } else { + $data['payment_pp_standard_status'] = $this->config->get('payment_pp_standard_status'); + } + + if (isset($this->request->post['payment_pp_standard_sort_order'])) { + $data['payment_pp_standard_sort_order'] = $this->request->post['payment_pp_standard_sort_order']; + } else { + $data['payment_pp_standard_sort_order'] = $this->config->get('payment_pp_standard_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_standard', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_standard')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_standard_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/realex.php b/public/admin/controller/extension/payment/realex.php new file mode 100644 index 0000000..e9c7547 --- /dev/null +++ b/public/admin/controller/extension/payment/realex.php @@ -0,0 +1,408 @@ +<?php +class ControllerExtensionPaymentRealex extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/realex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_realex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/realex/notify'; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/realex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/realex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_realex_merchant_id'])) { + $data['payment_realex_merchant_id'] = $this->request->post['payment_realex_merchant_id']; + } else { + $data['payment_realex_merchant_id'] = $this->config->get('payment_realex_merchant_id'); + } + + if (isset($this->request->post['payment_realex_secret'])) { + $data['payment_realex_secret'] = $this->request->post['payment_realex_secret']; + } else { + $data['payment_realex_secret'] = $this->config->get('payment_realex_secret'); + } + + if (isset($this->request->post['payment_realex_rebate_password'])) { + $data['payment_realex_rebate_password'] = $this->request->post['payment_realex_rebate_password']; + } else { + $data['payment_realex_rebate_password'] = $this->config->get('payment_realex_rebate_password'); + } + + if (isset($this->request->post['payment_realex_live_demo'])) { + $data['payment_realex_live_demo'] = $this->request->post['payment_realex_live_demo']; + } else { + $data['payment_realex_live_demo'] = $this->config->get('payment_realex_live_demo'); + } + + if (isset($this->request->post['payment_realex_geo_zone_id'])) { + $data['payment_realex_geo_zone_id'] = $this->request->post['payment_realex_geo_zone_id']; + } else { + $data['payment_realex_geo_zone_id'] = $this->config->get('payment_realex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_realex_total'])) { + $data['payment_realex_total'] = $this->request->post['payment_realex_total']; + } else { + $data['payment_realex_total'] = $this->config->get('payment_realex_total'); + } + + if (isset($this->request->post['payment_realex_sort_order'])) { + $data['payment_realex_sort_order'] = $this->request->post['payment_realex_sort_order']; + } else { + $data['payment_realex_sort_order'] = $this->config->get('payment_realex_sort_order'); + } + + if (isset($this->request->post['payment_realex_status'])) { + $data['payment_realex_status'] = $this->request->post['payment_realex_status']; + } else { + $data['payment_realex_status'] = $this->config->get('payment_realex_status'); + } + + if (isset($this->request->post['payment_realex_debug'])) { + $data['payment_realex_debug'] = $this->request->post['payment_realex_debug']; + } else { + $data['payment_realex_debug'] = $this->config->get('payment_realex_debug'); + } + + if (isset($this->request->post['payment_realex_account'])) { + $data['payment_realex_account'] = $this->request->post['payment_realex_account']; + } else { + $data['payment_realex_account'] = $this->config->get('payment_realex_account'); + } + + if (isset($this->request->post['payment_realex_auto_settle'])) { + $data['payment_realex_auto_settle'] = $this->request->post['payment_realex_auto_settle']; + } else { + $data['payment_realex_auto_settle'] = $this->config->get('payment_realex_auto_settle'); + } + + if (isset($this->request->post['payment_realex_card_select'])) { + $data['payment_realex_card_select'] = $this->request->post['payment_realex_card_select']; + } else { + $data['payment_realex_card_select'] = $this->config->get('payment_realex_card_select'); + } + + if (isset($this->request->post['payment_realex_tss_check'])) { + $data['payment_realex_tss_check'] = $this->request->post['payment_realex_tss_check']; + } else { + $data['payment_realex_tss_check'] = $this->config->get('payment_realex_tss_check'); + } + + if (isset($this->request->post['payment_realex_order_status_success_settled_id'])) { + $data['payment_realex_order_status_success_settled_id'] = $this->request->post['payment_realex_order_status_success_settled_id']; + } else { + $data['payment_realex_order_status_success_settled_id'] = $this->config->get('payment_realex_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_realex_order_status_success_unsettled_id'])) { + $data['payment_realex_order_status_success_unsettled_id'] = $this->request->post['payment_realex_order_status_success_unsettled_id']; + } else { + $data['payment_realex_order_status_success_unsettled_id'] = $this->config->get('payment_realex_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_id'])) { + $data['payment_realex_order_status_decline_id'] = $this->request->post['payment_realex_order_status_decline_id']; + } else { + $data['payment_realex_order_status_decline_id'] = $this->config->get('payment_realex_order_status_decline_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_pending_id'])) { + $data['payment_realex_order_status_decline_pending_id'] = $this->request->post['payment_realex_order_status_decline_pending_id']; + } else { + $data['payment_realex_order_status_decline_pending_id'] = $this->config->get('payment_realex_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_stolen_id'])) { + $data['payment_realex_order_status_decline_stolen_id'] = $this->request->post['payment_realex_order_status_decline_stolen_id']; + } else { + $data['payment_realex_order_status_decline_stolen_id'] = $this->config->get('payment_realex_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_bank_id'])) { + $data['payment_realex_order_status_decline_bank_id'] = $this->request->post['payment_realex_order_status_decline_bank_id']; + } else { + $data['payment_realex_order_status_decline_bank_id'] = $this->config->get('payment_realex_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_realex_live_url'])) { + $data['payment_realex_live_url'] = $this->request->post['payment_realex_live_url']; + } else { + $data['payment_realex_live_url'] = $this->config->get('payment_realex_live_url'); + } + + if (empty($data['payment_realex_live_url'])) { + $data['payment_realex_live_url'] = 'https://hpp.realexpayments.com/pay'; + } + + if (isset($this->request->post['payment_realex_demo_url'])) { + $data['payment_realex_demo_url'] = $this->request->post['payment_realex_demo_url']; + } else { + $data['payment_realex_demo_url'] = $this->config->get('payment_realex_demo_url'); + } + + if (empty($data['payment_realex_demo_url'])) { + $data['payment_realex_demo_url'] = 'https://hpp.sandbox.realexpayments.com/pay'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/realex', $data)); + } + + public function install() { + $this->load->model('extension/payment/realex'); + + $this->model_extension_payment_realex->install(); + } + + public function order() { + if ($this->config->get('payment_realex_status')) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->get['order_id']); + + if (!empty($realex_order)) { + $this->load->language('extension/payment/realex'); + + $realex_order['total_captured'] = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true); + $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true); + + $data['realex_order'] = $realex_order; + + $data['auto_settle'] = $realex_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/realex_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_realex->void($this->request->post['order_id']); + + $this->model_extension_payment_realex->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'void', 0.00); + $this->model_extension_payment_realex->updateVoidStatus($realex_order['realex_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_realex->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'payment', $this->request->post['amount']); + + $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) { + $this->model_extension_payment_realex->updateCaptureStatus($realex_order['realex_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_realex->updateForRebate($realex_order['realex_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_realex->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_realex->getTotalRebated($realex_order['realex_order_id']); + $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + if ($total_captured <= 0 && $realex_order['capture_status'] == 1) { + $this->model_extension_payment_realex->updateRebateStatus($realex_order['realex_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']*-1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/realex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_realex_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_realex_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_realex_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_realex_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/realex_remote.php b/public/admin/controller/extension/payment/realex_remote.php new file mode 100644 index 0000000..43e9e5a --- /dev/null +++ b/public/admin/controller/extension/payment/realex_remote.php @@ -0,0 +1,371 @@ +<?php +class ControllerExtensionPaymentRealexRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/realex_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_realex_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/realex_remote', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/realex_remote', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_realex_remote_merchant_id'])) { + $data['payment_realex_remote_merchant_id'] = $this->request->post['payment_realex_remote_merchant_id']; + } else { + $data['payment_realex_remote_merchant_id'] = $this->config->get('payment_realex_remote_merchant_id'); + } + + if (isset($this->request->post['payment_realex_remote_secret'])) { + $data['payment_realex_remote_secret'] = $this->request->post['payment_realex_remote_secret']; + } else { + $data['payment_realex_remote_secret'] = $this->config->get('payment_realex_remote_secret'); + } + + if (isset($this->request->post['payment_realex_remote_rebate_password'])) { + $data['payment_realex_remote_rebate_password'] = $this->request->post['payment_realex_remote_rebate_password']; + } else { + $data['payment_realex_remote_rebate_password'] = $this->config->get('payment_realex_remote_rebate_password'); + } + + if (isset($this->request->post['payment_realex_remote_geo_zone_id'])) { + $data['payment_realex_remote_geo_zone_id'] = $this->request->post['payment_realex_remote_geo_zone_id']; + } else { + $data['payment_realex_remote_geo_zone_id'] = $this->config->get('payment_realex_remote_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_realex_remote_total'])) { + $data['payment_realex_remote_total'] = $this->request->post['payment_realex_remote_total']; + } else { + $data['payment_realex_remote_total'] = $this->config->get('payment_realex_remote_total'); + } + + if (isset($this->request->post['payment_realex_remote_sort_order'])) { + $data['payment_realex_remote_sort_order'] = $this->request->post['payment_realex_remote_sort_order']; + } else { + $data['payment_realex_remote_sort_order'] = $this->config->get('payment_realex_remote_sort_order'); + } + + if (isset($this->request->post['payment_realex_remote_status'])) { + $data['payment_realex_remote_status'] = $this->request->post['payment_realex_remote_status']; + } else { + $data['payment_realex_remote_status'] = $this->config->get('payment_realex_remote_status'); + } + + if (isset($this->request->post['payment_realex_remote_card_data_status'])) { + $data['payment_realex_remote_card_data_status'] = $this->request->post['payment_realex_remote_card_data_status']; + } else { + $data['payment_realex_remote_card_data_status'] = $this->config->get('payment_realex_remote_card_data_status'); + } + + if (isset($this->request->post['payment_realex_remote_debug'])) { + $data['payment_realex_remote_debug'] = $this->request->post['payment_realex_remote_debug']; + } else { + $data['payment_realex_remote_debug'] = $this->config->get('payment_realex_remote_debug'); + } + + if (isset($this->request->post['payment_realex_remote_account'])) { + $data['payment_realex_remote_account'] = $this->request->post['payment_realex_remote_account']; + } else { + $data['payment_realex_remote_account'] = $this->config->get('payment_realex_remote_account'); + } + + if (isset($this->request->post['payment_realex_remote_auto_settle'])) { + $data['payment_realex_remote_auto_settle'] = $this->request->post['payment_realex_remote_auto_settle']; + } else { + $data['payment_realex_remote_auto_settle'] = $this->config->get('payment_realex_remote_auto_settle'); + } + + if (isset($this->request->post['payment_realex_remote_tss_check'])) { + $data['payment_realex_remote_tss_check'] = $this->request->post['payment_realex_remote_tss_check']; + } else { + $data['payment_realex_remote_tss_check'] = $this->config->get('payment_realex_remote_tss_check'); + } + + if (isset($this->request->post['payment_realex_remote_3d'])) { + $data['payment_realex_remote_3d'] = $this->request->post['payment_realex_remote_3d']; + } else { + $data['payment_realex_remote_3d'] = $this->config->get('payment_realex_remote_3d'); + } + + if (isset($this->request->post['payment_realex_remote_liability'])) { + $data['payment_realex_remote_liability'] = $this->request->post['payment_realex_remote_liability']; + } else { + $data['payment_realex_remote_liability'] = $this->config->get('payment_realex_remote_liability'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_success_settled_id'])) { + $data['payment_realex_remote_order_status_success_settled_id'] = $this->request->post['payment_realex_remote_order_status_success_settled_id']; + } else { + $data['payment_realex_remote_order_status_success_settled_id'] = $this->config->get('payment_realex_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_success_unsettled_id'])) { + $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->request->post['payment_realex_remote_order_status_success_unsettled_id']; + } else { + $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->config->get('payment_realex_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_id'])) { + $data['payment_realex_remote_order_status_decline_id'] = $this->request->post['payment_realex_remote_order_status_decline_id']; + } else { + $data['payment_realex_remote_order_status_decline_id'] = $this->config->get('payment_realex_remote_order_status_decline_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_pending_id'])) { + $data['payment_realex_remote_order_status_decline_pending_id'] = $this->request->post['payment_realex_remote_order_status_decline_pending_id']; + } else { + $data['payment_realex_remote_order_status_decline_pending_id'] = $this->config->get('payment_realex_remote_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_stolen_id'])) { + $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->request->post['payment_realex_remote_order_status_decline_stolen_id']; + } else { + $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->config->get('payment_realex_remote_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_bank_id'])) { + $data['payment_realex_remote_order_status_decline_bank_id'] = $this->request->post['payment_realex_remote_order_status_decline_bank_id']; + } else { + $data['payment_realex_remote_order_status_decline_bank_id'] = $this->config->get('payment_realex_remote_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/realex_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/realex_remote'); + $this->model_extension_payment_realex_remote->install(); + } + + public function order() { + if ($this->config->get('payment_realex_remote_status')) { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->get['order_id']); + + if (!empty($realex_order)) { + $this->load->language('extension/payment/realex_remote'); + + $realex_order['total_captured'] = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true); + $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true); + + $data['realex_order'] = $realex_order; + + $data['auto_settle'] = $realex_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/realex_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/realex_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_realex_remote->void($this->request->post['order_id']); + + $this->model_extension_payment_realex_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'void', 0.00); + $this->model_extension_payment_realex_remote->updateVoidStatus($realex_order['realex_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_realex_remote->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'payment', $this->request->post['amount']); + $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) { + $this->model_extension_payment_realex_remote->updateCaptureStatus($realex_order['realex_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_realex_remote->updateForRebate($realex_order['realex_remote_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $realex_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/realex_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_realex_remote->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_realex_remote->getTotalRebated($realex_order['realex_remote_order_id']); + $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + if ($total_captured <= 0 && $realex_order['capture_status'] == 1) { + $this->model_extension_payment_realex_remote->updateRebateStatus($realex_order['realex_remote_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/realex_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_realex_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_realex_remote_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/sagepay_direct.php b/public/admin/controller/extension/payment/sagepay_direct.php new file mode 100644 index 0000000..22c5bbe --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_direct.php @@ -0,0 +1,327 @@ +<?php +class ControllerExtensionPaymentSagepayDirect extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/sagepay_direct'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_direct', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_direct', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_direct', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_direct_vendor'])) { + $data['payment_sagepay_direct_vendor'] = $this->request->post['payment_sagepay_direct_vendor']; + } else { + $data['payment_sagepay_direct_vendor'] = $this->config->get('payment_sagepay_direct_vendor'); + } + + if (isset($this->request->post['payment_sagepay_direct_password'])) { + $data['payment_sagepay_direct_password'] = $this->request->post['payment_sagepay_direct_password']; + } else { + $data['payment_sagepay_direct_password'] = $this->config->get('payment_sagepay_direct_password'); + } + + if (isset($this->request->post['payment_sagepay_direct_test'])) { + $data['payment_sagepay_direct_test'] = $this->request->post['payment_sagepay_direct_test']; + } else { + $data['payment_sagepay_direct_test'] = $this->config->get('payment_sagepay_direct_test'); + } + + if (isset($this->request->post['payment_sagepay_direct_transaction'])) { + $data['payment_sagepay_direct_transaction'] = $this->request->post['payment_sagepay_direct_transaction']; + } else { + $data['payment_sagepay_direct_transaction'] = $this->config->get('payment_sagepay_direct_transaction'); + } + + if (isset($this->request->post['payment_sagepay_direct_total'])) { + $data['payment_sagepay_direct_total'] = $this->request->post['payment_sagepay_direct_total']; + } else { + $data['payment_sagepay_direct_total'] = $this->config->get('payment_sagepay_direct_total'); + } + + if (isset($this->request->post['payment_sagepay_direct_card'])) { + $data['payment_sagepay_direct_card'] = $this->request->post['payment_sagepay_direct_card']; + } else { + $data['payment_sagepay_direct_card'] = $this->config->get('payment_sagepay_direct_card'); + } + + if (isset($this->request->post['payment_sagepay_direct_order_status_id'])) { + $data['payment_sagepay_direct_order_status_id'] = $this->request->post['payment_sagepay_direct_order_status_id']; + } else { + $data['payment_sagepay_direct_order_status_id'] = $this->config->get('payment_sagepay_direct_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_direct_geo_zone_id'])) { + $data['payment_sagepay_direct_geo_zone_id'] = $this->request->post['payment_sagepay_direct_geo_zone_id']; + } else { + $data['payment_sagepay_direct_geo_zone_id'] = $this->config->get('payment_sagepay_direct_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_direct_status'])) { + $data['payment_sagepay_direct_status'] = $this->request->post['payment_sagepay_direct_status']; + } else { + $data['payment_sagepay_direct_status'] = $this->config->get('payment_sagepay_direct_status'); + } + + if (isset($this->request->post['payment_sagepay_direct_debug'])) { + $data['payment_sagepay_direct_debug'] = $this->request->post['payment_sagepay_direct_debug']; + } else { + $data['payment_sagepay_direct_debug'] = $this->config->get('payment_sagepay_direct_debug'); + } + + if (isset($this->request->post['payment_sagepay_direct_sort_order'])) { + $data['payment_sagepay_direct_sort_order'] = $this->request->post['payment_sagepay_direct_sort_order']; + } else { + $data['payment_sagepay_direct_sort_order'] = $this->config->get('payment_sagepay_direct_sort_order'); + } + + if (isset($this->request->post['payment_sagepay_direct_cron_job_token'])) { + $data['payment_sagepay_direct_cron_job_token'] = $this->request->post['payment_sagepay_direct_cron_job_token']; + } elseif ($this->config->get('payment_sagepay_direct_cron_job_token')) { + $data['payment_sagepay_direct_cron_job_token'] = $this->config->get('payment_sagepay_direct_cron_job_token'); + } else { + $data['payment_sagepay_direct_cron_job_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['sagepay_direct_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_direct/cron&token=' . $data['payment_sagepay_direct_cron_job_token']; + + if ($this->config->get('payment_sagepay_direct_last_cron_job_run')) { + $data['payment_sagepay_direct_last_cron_job_run'] = $this->config->get('payment_sagepay_direct_last_cron_job_run'); + } else { + $data['payment_sagepay_direct_last_cron_job_run'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_direct', $data)); + } + + public function install() { + $this->load->model('extension/payment/sagepay_direct'); + $this->model_extension_payment_sagepay_direct->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/sagepay_direct'); + $this->model_extension_payment_sagepay_direct->uninstall(); + } + + public function order() { + if ($this->config->get('payment_sagepay_direct_status')) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->get['order_id']); + + if (!empty($sagepay_direct_order)) { + $this->load->language('extension/payment/sagepay_direct'); + + $sagepay_direct_order['total_released'] = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + $sagepay_direct_order['total_formatted'] = $this->currency->format($sagepay_direct_order['total'], $sagepay_direct_order['currency_code'], false, false); + $sagepay_direct_order['total_released_formatted'] = $this->currency->format($sagepay_direct_order['total_released'], $sagepay_direct_order['currency_code'], false, false); + + $data['sagepay_direct_order'] = $sagepay_direct_order; + + $data['auto_settle'] = $sagepay_direct_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/sagepay_direct_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_sagepay_direct->void($this->request->post['order_id']); + + $this->model_extension_payment_sagepay_direct->logger('Void result', $void_response); + + if ($void_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'void', 0.00); + $this->model_extension_payment_sagepay_direct->updateVoidStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_sagepay_direct->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_direct->logger('Release result', $release_response); + + if ($release_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'payment', $this->request->post['amount']); + + $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + if ($total_released >= $sagepay_direct_order['total'] || $sagepay_direct_order['settle_type'] == 0) { + $this->model_extension_payment_sagepay_direct->updateReleaseStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_sagepay_direct->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_direct->logger('Rebate result', $rebate_response); + + if ($rebate_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_sagepay_direct->getTotalRebated($sagepay_direct_order['sagepay_direct_order_id']); + $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + if ($total_released <= 0 && $sagepay_direct_order['release_status'] == 1) { + $this->model_extension_payment_sagepay_direct->updateRebateStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_direct')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_direct_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/sagepay_server.php b/public/admin/controller/extension/payment/sagepay_server.php new file mode 100644 index 0000000..6bd0427 --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_server.php @@ -0,0 +1,328 @@ +<?php +class ControllerExtensionPaymentSagepayServer extends Controller { + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/sagepay_server'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_server', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_server', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_server', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_server_vendor'])) { + $data['payment_sagepay_server_vendor'] = $this->request->post['payment_sagepay_server_vendor']; + } else { + $data['payment_sagepay_server_vendor'] = $this->config->get('payment_sagepay_server_vendor'); + } + + if (isset($this->request->post['payment_sagepay_server_password'])) { + $data['payment_sagepay_server_password'] = $this->request->post['payment_sagepay_server_password']; + } else { + $data['payment_sagepay_server_password'] = $this->config->get('payment_sagepay_server_password'); + } + + if (isset($this->request->post['payment_sagepay_server_test'])) { + $data['payment_sagepay_server_test'] = $this->request->post['payment_sagepay_server_test']; + } else { + $data['payment_sagepay_server_test'] = $this->config->get('payment_sagepay_server_test'); + } + + if (isset($this->request->post['payment_sagepay_server_transaction'])) { + $data['payment_sagepay_server_transaction'] = $this->request->post['payment_sagepay_server_transaction']; + } else { + $data['payment_sagepay_server_transaction'] = $this->config->get('payment_sagepay_server_transaction'); + } + + if (isset($this->request->post['payment_sagepay_server_total'])) { + $data['payment_sagepay_server_total'] = $this->request->post['payment_sagepay_server_total']; + } else { + $data['payment_sagepay_server_total'] = $this->config->get('payment_sagepay_server_total'); + } + + if (isset($this->request->post['payment_sagepay_server_card'])) { + $data['payment_sagepay_server_card'] = $this->request->post['payment_sagepay_server_card']; + } else { + $data['payment_sagepay_server_card'] = $this->config->get('payment_sagepay_server_card'); + } + + if (isset($this->request->post['payment_sagepay_server_order_status_id'])) { + $data['payment_sagepay_server_order_status_id'] = $this->request->post['payment_sagepay_server_order_status_id']; + } else { + $data['payment_sagepay_server_order_status_id'] = $this->config->get('payment_sagepay_server_order_status_id'); + } + + if (isset($this->request->post['payment_sagepay_server_cron_job_token'])) { + $data['payment_sagepay_server_cron_job_token'] = $this->request->post['payment_sagepay_server_cron_job_token']; + } elseif ($this->config->get('payment_sagepay_server_cron_job_token')) { + $data['payment_sagepay_server_cron_job_token'] = $this->config->get('payment_sagepay_server_cron_job_token'); + } else { + $data['payment_sagepay_server_cron_job_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['sagepay_server_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_server/cron&token=' . $data['payment_sagepay_server_cron_job_token']; + + if ($this->config->get('payment_sagepay_server_last_cron_job_run')) { + $data['payment_sagepay_server_last_cron_job_run'] = $this->config->get('payment_sagepay_server_last_cron_job_run'); + } else { + $data['payment_sagepay_server_last_cron_job_run'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_server_geo_zone_id'])) { + $data['payment_sagepay_server_geo_zone_id'] = $this->request->post['payment_sagepay_server_geo_zone_id']; + } else { + $data['payment_sagepay_server_geo_zone_id'] = $this->config->get('payment_sagepay_server_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_server_status'])) { + $data['payment_sagepay_server_status'] = $this->request->post['payment_sagepay_server_status']; + } else { + $data['payment_sagepay_server_status'] = $this->config->get('payment_sagepay_server_status'); + } + + if (isset($this->request->post['payment_sagepay_server_debug'])) { + $data['payment_sagepay_server_debug'] = $this->request->post['payment_sagepay_server_debug']; + } else { + $data['payment_sagepay_server_debug'] = $this->config->get('payment_sagepay_server_debug'); + } + + if (isset($this->request->post['payment_sagepay_server_sort_order'])) { + $data['payment_sagepay_server_sort_order'] = $this->request->post['payment_sagepay_server_sort_order']; + } else { + $data['payment_sagepay_server_sort_order'] = $this->config->get('payment_sagepay_server_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_server', $data)); + } + + public function install() { + $this->load->model('extension/payment/sagepay_server'); + $this->model_extension_payment_sagepay_server->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/sagepay_server'); + $this->model_extension_payment_sagepay_server->uninstall(); + } + + public function order() { + if ($this->config->get('payment_sagepay_server_status')) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->get['order_id']); + + if (!empty($sagepay_server_order)) { + $this->load->language('extension/payment/sagepay_server'); + + $sagepay_server_order['total_released'] = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + $sagepay_server_order['total_formatted'] = $this->currency->format($sagepay_server_order['total'], $sagepay_server_order['currency_code'], false, false); + $sagepay_server_order['total_released_formatted'] = $this->currency->format($sagepay_server_order['total_released'], $sagepay_server_order['currency_code'], false, false); + + $data['sagepay_server_order'] = $sagepay_server_order; + + $data['auto_settle'] = $sagepay_server_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/sagepay_server_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_sagepay_server->void($this->request->post['order_id']); + + $this->model_extension_payment_sagepay_server->logger('Void result', $void_response); + + if ($void_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'void', 0.00); + $this->model_extension_payment_sagepay_server->updateVoidStatus($sagepay_server_order['sagepay_server_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_sagepay_server->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_server->logger('Release result', $release_response); + + if ($release_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'payment', $this->request->post['amount']); + + $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + if ($total_released >= $sagepay_server_order['total'] || $sagepay_server_order['settle_type'] == 0) { + $this->model_extension_payment_sagepay_server->updateReleaseStatus($sagepay_server_order['sagepay_server_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_sagepay_server->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_server->logger('Rebate result', $rebate_response); + + if ($rebate_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_sagepay_server->getTotalRebated($sagepay_server_order['sagepay_server_order_id']); + $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + if ($total_released <= 0 && $sagepay_server_order['release_status'] == 1) { + $this->model_extension_payment_sagepay_server->updateRebateStatus($sagepay_server_order['sagepay_server_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_server')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_server_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/sagepay_us.php b/public/admin/controller/extension/payment/sagepay_us.php new file mode 100644 index 0000000..1a92ba7 --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_us.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionPaymentSagepayUS extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/sagepay_us'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_us', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant_id'])) { + $data['error_merchant_id'] = $this->error['merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['merchant_key'])) { + $data['error_merchant_key'] = $this->error['merchant_key']; + } else { + $data['error_merchant_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_us', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_us', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_us_merchant_id'])) { + $data['payment_sagepay_us_merchant_id'] = $this->request->post['payment_sagepay_us_merchant_id']; + } else { + $data['payment_sagepay_us_merchant_id'] = $this->config->get('payment_sagepay_us_merchant_id'); + } + + if (isset($this->request->post['payment_sagepay_us_merchant_key'])) { + $data['payment_sagepay_us_merchant_key'] = $this->request->post['payment_sagepay_us_merchant_key']; + } else { + $data['payment_sagepay_us_merchant_key'] = $this->config->get('payment_sagepay_us_merchant_key'); + } + + if (isset($this->request->post['payment_sagepay_us_total'])) { + $data['payment_sagepay_us_total'] = $this->request->post['payment_sagepay_us_total']; + } else { + $data['payment_sagepay_us_total'] = $this->config->get('payment_sagepay_us_total'); + } + + if (isset($this->request->post['payment_sagepay_us_order_status_id'])) { + $data['payment_sagepay_us_order_status_id'] = $this->request->post['payment_sagepay_us_order_status_id']; + } else { + $data['payment_sagepay_us_order_status_id'] = $this->config->get('payment_sagepay_us_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_us_geo_zone_id'])) { + $data['payment_sagepay_us_geo_zone_id'] = $this->request->post['payment_sagepay_us_geo_zone_id']; + } else { + $data['payment_sagepay_us_geo_zone_id'] = $this->config->get('payment_sagepay_us_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_us_status'])) { + $data['payment_sagepay_us_status'] = $this->request->post['payment_sagepay_us_status']; + } else { + $data['payment_sagepay_us_status'] = $this->config->get('payment_sagepay_us_status'); + } + + if (isset($this->request->post['payment_sagepay_us_sort_order'])) { + $data['payment_sagepay_us_sort_order'] = $this->request->post['payment_sagepay_us_sort_order']; + } else { + $data['payment_sagepay_us_sort_order'] = $this->config->get('payment_sagepay_us_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_us', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_us')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_us_merchant_id']) { + $this->error['merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_sagepay_us_merchant_key']) { + $this->error['merchant_key'] = $this->language->get('error_merchant_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/securetrading_pp.php b/public/admin/controller/extension/payment/securetrading_pp.php new file mode 100644 index 0000000..de4850c --- /dev/null +++ b/public/admin/controller/extension/payment/securetrading_pp.php @@ -0,0 +1,475 @@ +<?php +class ControllerExtensionPaymentSecureTradingPp extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + $this->load->language('extension/payment/securetrading_pp'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->request->post['payment_securetrading_pp_site_reference'] = trim($this->request->post['payment_securetrading_pp_site_reference']); + + $this->model_setting_setting->editSetting('payment_securetrading_pp', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->request->post['payment_securetrading_pp_site_reference'])) { + $data['payment_securetrading_pp_site_reference'] = $this->request->post['payment_securetrading_pp_site_reference']; + } else { + $data['payment_securetrading_pp_site_reference'] = $this->config->get('payment_securetrading_pp_site_reference'); + } + + if (isset($this->request->post['payment_securetrading_pp_username'])) { + $data['payment_securetrading_pp_username'] = $this->request->post['payment_securetrading_pp_username']; + } else { + $data['payment_securetrading_pp_username'] = $this->config->get('payment_securetrading_pp_username'); + } + + if (isset($this->request->post['payment_securetrading_pp_password'])) { + $data['payment_securetrading_pp_password'] = $this->request->post['payment_securetrading_pp_password']; + } else { + $data['payment_securetrading_pp_password'] = $this->config->get('payment_securetrading_pp_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_notification_password'])) { + $data['payment_securetrading_pp_notification_password'] = $this->request->post['payment_securetrading_pp_notification_password']; + } else { + $data['payment_securetrading_pp_notification_password'] = $this->config->get('payment_securetrading_pp_notification_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_site_security_password'])) { + $data['payment_securetrading_pp_site_security_password'] = $this->request->post['payment_securetrading_pp_site_security_password']; + } else { + $data['payment_securetrading_pp_site_security_password'] = $this->config->get('payment_securetrading_pp_site_security_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_site_security_status'])) { + $data['payment_securetrading_pp_site_security_status'] = $this->request->post['payment_securetrading_pp_site_security_status']; + } else { + $data['payment_securetrading_pp_site_security_status'] = $this->config->get('payment_securetrading_pp_site_security_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_webservice_username'])) { + $data['payment_securetrading_pp_webservice_username'] = $this->request->post['payment_securetrading_pp_webservice_username']; + } else { + $data['payment_securetrading_pp_webservice_username'] = $this->config->get('payment_securetrading_pp_webservice_username'); + } + + if (isset($this->request->post['payment_securetrading_pp_webservice_password'])) { + $data['payment_securetrading_pp_webservice_password'] = $this->request->post['payment_securetrading_pp_webservice_password']; + } else { + $data['payment_securetrading_pp_webservice_password'] = $this->config->get('payment_securetrading_pp_webservice_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_order_status_id'])) { + $data['payment_securetrading_pp_order_status_id'] = $this->request->post['payment_securetrading_pp_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_order_status_id') != '') { + $data['payment_securetrading_pp_order_status_id'] = $this->config->get('payment_securetrading_pp_order_status_id'); + } else { + $data['payment_securetrading_pp_order_status_id'] = 1; + } + + if (isset($this->request->post['payment_securetrading_pp_declined_order_status_id'])) { + $data['payment_securetrading_pp_declined_order_status_id'] = $this->request->post['payment_securetrading_pp_declined_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_declined_order_status_id') != '') { + $data['payment_securetrading_pp_declined_order_status_id'] = $this->config->get('payment_securetrading_pp_declined_order_status_id'); + } else { + $data['payment_securetrading_pp_declined_order_status_id'] = 8; + } + + if (isset($this->request->post['payment_securetrading_pp_refunded_order_status_id'])) { + $data['payment_securetrading_pp_refunded_order_status_id'] = $this->request->post['payment_securetrading_pp_refunded_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_refunded_order_status_id') != '') { + $data['payment_securetrading_pp_refunded_order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id'); + } else { + $data['payment_securetrading_pp_refunded_order_status_id'] = 11; + } + + if (isset($this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id'])) { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id') != '') { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id'); + } else { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = 12; + } + + if (isset($this->request->post['payment_securetrading_pp_settle_status'])) { + $data['payment_securetrading_pp_settle_status'] = $this->request->post['payment_securetrading_pp_settle_status']; + } else { + $data['payment_securetrading_pp_settle_status'] = $this->config->get('payment_securetrading_pp_settle_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_settle_due_date'])) { + $data['payment_securetrading_pp_settle_due_date'] = $this->request->post['payment_securetrading_pp_settle_due_date']; + } else { + $data['payment_securetrading_pp_settle_due_date'] = $this->config->get('payment_securetrading_pp_settle_due_date'); + } + + if (isset($this->request->post['payment_securetrading_pp_geo_zone_id'])) { + $data['payment_securetrading_pp_geo_zone_id'] = $this->request->post['payment_securetrading_pp_geo_zone_id']; + } else { + $data['payment_securetrading_pp_geo_zone_id'] = $this->config->get('payment_securetrading_pp_geo_zone_id'); + } + + if (isset($this->request->post['payment_securetrading_pp_status'])) { + $data['payment_securetrading_pp_status'] = $this->request->post['payment_securetrading_pp_status']; + } else { + $data['payment_securetrading_pp_status'] = $this->config->get('payment_securetrading_pp_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_sort_order'])) { + $data['payment_securetrading_pp_sort_order'] = $this->request->post['payment_securetrading_pp_sort_order']; + } else { + $data['payment_securetrading_pp_sort_order'] = $this->config->get('payment_securetrading_pp_sort_order'); + } + + if (isset($this->request->post['payment_securetrading_pp_total'])) { + $data['payment_securetrading_pp_total'] = $this->request->post['payment_securetrading_pp_total']; + } else { + $data['payment_securetrading_pp_total'] = $this->config->get('payment_securetrading_pp_total'); + } + + if (isset($this->request->post['payment_securetrading_pp_parent_css'])) { + $data['payment_securetrading_pp_parent_css'] = $this->request->post['payment_securetrading_pp_parent_css']; + } else { + $data['payment_securetrading_pp_parent_css'] = $this->config->get('payment_securetrading_pp_parent_css'); + } + + if (isset($this->request->post['payment_securetrading_pp_child_css'])) { + $data['payment_securetrading_pp_child_css'] = $this->request->post['payment_securetrading_pp_child_css']; + } else { + $data['payment_securetrading_pp_child_css'] = $this->config->get('payment_securetrading_pp_child_css'); + } + + if (isset($this->request->post['payment_securetrading_pp_cards_accepted'])) { + $data['payment_securetrading_pp_cards_accepted'] = $this->request->post['payment_securetrading_pp_cards_accepted']; + } else { + $data['payment_securetrading_pp_cards_accepted'] = $this->config->get('payment_securetrading_pp_cards_accepted'); + + if ($data['payment_securetrading_pp_cards_accepted'] == null) { + $data['payment_securetrading_pp_cards_accepted'] = array(); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['site_reference'])) { + $data['error_site_reference'] = $this->error['site_reference']; + } else { + $data['error_site_reference'] = ''; + } + + if (isset($this->error['cards_accepted'])) { + $data['error_cards_accepted'] = $this->error['cards_accepted']; + } else { + $data['error_cards_accepted'] = ''; + } + + if (isset($this->error['notification_password'])) { + $data['error_notification_password'] = $this->error['notification_password']; + } else { + $data['error_notification_password'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/securetrading_pp', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['cards'] = array( + 'AMEX' => 'American Express', + 'VISA' => 'Visa', + 'DELTA' => 'Visa Debit', + 'ELECTRON' => 'Visa Electron', + 'PURCHASING' => 'Visa Purchasing', + 'VPAY' => 'V Pay', + 'MASTERCARD' => 'MasterCard', + 'MASTERCARDDEBIT' => 'MasterCard Debit', + 'MAESTRO' => 'Maestro', + 'PAYPAL' => 'PayPal', + ); + + $data['settlement_statuses'] = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_pending_settlement_manually_overriden'), + '2' => $this->language->get('text_pending_suspended'), + '100' => $this->language->get('text_pending_settled'), + ); + + $data['action'] = $this->url->link('extension/payment/securetrading_pp', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/securetrading_pp', $data)); + } + + public function install() { + $this->load->model('extension/payment/securetrading_pp'); + $this->model_extension_payment_securetrading_pp->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/securetrading_pp'); + $this->model_extension_payment_securetrading_pp->uninstall(); + } + + public function order() { + if ($this->config->get('payment_securetrading_pp_status')) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->get['order_id']); + + if (!empty($securetrading_pp_order)) { + $this->load->language('extension/payment/securetrading_pp'); + + $securetrading_pp_order['total_released'] = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + $securetrading_pp_order['total_formatted'] = $this->currency->format($securetrading_pp_order['total'], $securetrading_pp_order['currency_code'], false, false); + $securetrading_pp_order['total_released_formatted'] = $this->currency->format($securetrading_pp_order['total_released'], $securetrading_pp_order['currency_code'], false, false); + + $data['securetrading_pp_order'] = $securetrading_pp_order; + + $data['auto_settle'] = $securetrading_pp_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/securetrading_pp_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_securetrading_pp->void($this->request->post['order_id']); + + $this->model_extension_payment_securetrading_pp->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response !== false) { + $response_xml = simplexml_load_string($void_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['msg'] = (string)$response_xml->response->error->message; + $json['error'] = true; + } else { + + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'reversed', 0.00); + $this->model_extension_payment_securetrading_pp->updateVoidStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + + $this->data = array( + 'order_status_id' => $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id'), + 'notify' => false, + 'comment' => '', + ); + + $this->load->model('sale/order'); + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data); + + $json['msg'] = $this->language->get('text_authorisation_reversed'); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } + } else { + $json['msg'] = $this->language->get('error_connection'); + $json['error'] = true; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + $amount = number_format($this->request->post['amount'], 2); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_securetrading_pp->release($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_pp->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response !== false) { + $response_xml = simplexml_load_string($release_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } else { + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'payment', $amount); + + $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + if ($total_released >= $securetrading_pp_order['total'] || $securetrading_pp_order['settle_type'] == 100) { + $this->model_extension_payment_securetrading_pp->updateReleaseStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('securetrading_pp_order_status_success_settled_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (double)$total_released; + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $amount = number_format($this->request->post['amount'], 2); + + $rebate_response = $this->model_extension_payment_securetrading_pp->rebate($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_pp->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response !== false) { + $response_xml = simplexml_load_string($rebate_response); + + $error_code = (string)$response_xml->response->error->code; + + if ($error_code == '0') { + + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'rebate', $amount * -1); + + $total_rebated = $this->model_extension_payment_securetrading_pp->getTotalRebated($securetrading_pp_order['securetrading_pp_order_id']); + $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + if ($total_released <= 0 && $securetrading_pp_order['release_status'] == 1) { + $json['status'] = 1; + $json['message'] = $this->language->get('text_refund_issued'); + + $this->model_extension_payment_securetrading_pp->updateRebateStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount * -1; + $json['data']['total_released'] = (double)$total_released; + $json['data']['total_rebated'] = (double)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } + } else { + $json['status'] = 0; + $json['message'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_securetrading_pp_site_reference']) { + $this->error['site_reference'] = $this->language->get('error_site_reference'); + } + + if (empty($this->request->post['payment_securetrading_pp_cards_accepted'])) { + $this->error['cards_accepted'] = $this->language->get('error_cards_accepted'); + } + + if (!$this->request->post['payment_securetrading_pp_notification_password']) { + $this->error['notification_password'] = $this->language->get('error_notification_password'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/securetrading_ws.php b/public/admin/controller/extension/payment/securetrading_ws.php new file mode 100644 index 0000000..8e702ec --- /dev/null +++ b/public/admin/controller/extension/payment/securetrading_ws.php @@ -0,0 +1,570 @@ +<?php +class ControllerExtensionPaymentSecureTradingWs extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + $this->load->model('localisation/currency'); + $this->load->language('extension/payment/securetrading_ws'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->request->post['payment_securetrading_ws_site_reference'] = trim($this->request->post['payment_securetrading_ws_site_reference']); + $this->request->post['payment_securetrading_ws_username'] = trim($this->request->post['payment_securetrading_ws_username']); + + $this->model_setting_setting->editSetting('payment_securetrading_ws', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->request->post['payment_securetrading_ws_site_reference'])) { + $data['payment_securetrading_ws_site_reference'] = $this->request->post['payment_securetrading_ws_site_reference']; + } else { + $data['payment_securetrading_ws_site_reference'] = $this->config->get('payment_securetrading_ws_site_reference'); + } + + if (isset($this->request->post['payment_securetrading_ws_username'])) { + $data['payment_securetrading_ws_username'] = $this->request->post['payment_securetrading_ws_username']; + } else { + $data['payment_securetrading_ws_username'] = $this->config->get('payment_securetrading_ws_username'); + } + + if (isset($this->request->post['payment_securetrading_ws_password'])) { + $data['payment_securetrading_ws_password'] = $this->request->post['payment_securetrading_ws_password']; + } else { + $data['payment_securetrading_ws_password'] = $this->config->get('payment_securetrading_ws_password'); + } + + if (isset($this->request->post['payment_securetrading_ws_csv_username'])) { + $data['payment_securetrading_ws_csv_username'] = $this->request->post['payment_securetrading_ws_csv_username']; + } else { + $data['payment_securetrading_ws_csv_username'] = $this->config->get('payment_securetrading_ws_csv_username'); + } + + if (isset($this->request->post['payment_securetrading_ws_csv_password'])) { + $data['payment_securetrading_ws_csv_password'] = $this->request->post['payment_securetrading_ws_csv_password']; + } else { + $data['payment_securetrading_ws_csv_password'] = $this->config->get('payment_securetrading_ws_csv_password'); + } + + $this->config->set('payment_securetrading_ws_3d_secure', 1); + + if (isset($this->request->post['payment_securetrading_ws_3d_secure'])) { + $data['payment_securetrading_ws_3d_secure'] = $this->request->post['payment_securetrading_ws_3d_secure']; + } else { + $data['payment_securetrading_ws_3d_secure'] = $this->config->get('payment_securetrading_ws_3d_secure'); + } + + if (isset($this->request->post['payment_securetrading_ws_cards_accepted'])) { + $data['payment_securetrading_ws_cards_accepted'] = $this->request->post['payment_securetrading_ws_cards_accepted']; + } else { + $data['payment_securetrading_ws_cards_accepted'] = $this->config->get('payment_securetrading_ws_cards_accepted'); + + if ($data['payment_securetrading_ws_cards_accepted'] == null) { + $data['payment_securetrading_ws_cards_accepted'] = array(); + } + } + + if (isset($this->request->post['payment_securetrading_ws_order_status_id'])) { + $data['payment_securetrading_ws_order_status_id'] = $this->request->post['payment_securetrading_ws_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_order_status_id') != '') { + $data['payment_securetrading_ws_order_status_id'] = $this->config->get('payment_securetrading_ws_order_status_id'); + } else { + $data['payment_securetrading_ws_order_status_id'] = 1; + } + + if (isset($this->request->post['payment_securetrading_ws_failed_order_status_id'])) { + $data['payment_securetrading_ws_failed_order_status_id'] = $this->request->post['payment_securetrading_ws_failed_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_failed_order_status_id') != '') { + $data['payment_securetrading_ws_failed_order_status_id'] = $this->config->get('payment_securetrading_ws_failed_order_status_id'); + } else { + $data['payment_securetrading_ws_failed_order_status_id'] = 10; + } + + if (isset($this->request->post['payment_securetrading_ws_declined_order_status_id'])) { + $data['payment_securetrading_ws_declined_order_status_id'] = $this->request->post['payment_securetrading_ws_declined_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_declined_order_status_id') != '') { + $data['payment_securetrading_ws_declined_order_status_id'] = $this->config->get('payment_securetrading_ws_declined_order_status_id'); + } else { + $data['payment_securetrading_ws_declined_order_status_id'] = 8; + } + + if (isset($this->request->post['payment_securetrading_ws_refunded_order_status_id'])) { + $data['payment_securetrading_ws_refunded_order_status_id'] = $this->request->post['payment_securetrading_ws_refunded_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_refunded_order_status_id') != '') { + $data['payment_securetrading_ws_refunded_order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id'); + } else { + $data['payment_securetrading_ws_refunded_order_status_id'] = 11; + } + + if (isset($this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id'])) { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id') != '') { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id'); + } else { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = 12; + } + + if (isset($this->request->post['payment_securetrading_ws_settle_status'])) { + $data['payment_securetrading_ws_settle_status'] = $this->request->post['payment_securetrading_ws_settle_status']; + } else { + $data['payment_securetrading_ws_settle_status'] = $this->config->get('payment_securetrading_ws_settle_status'); + } + + if (isset($this->request->post['payment_securetrading_ws_settle_due_date'])) { + $data['payment_securetrading_ws_settle_due_date'] = $this->request->post['payment_securetrading_ws_settle_due_date']; + } else { + $data['payment_securetrading_ws_settle_due_date'] = $this->config->get('payment_securetrading_ws_settle_due_date'); + } + + if (isset($this->request->post['payment_securetrading_ws_geo_zone'])) { + $data['payment_securetrading_ws_geo_zone_id'] = $this->request->post['payment_securetrading_ws_geo_zone_id']; + } else { + $data['payment_securetrading_ws_geo_zone_id'] = $this->config->get('payment_securetrading_ws_geo_zone_id'); + } + + if (isset($this->request->post['payment_securetrading_ws_status'])) { + $data['payment_securetrading_ws_status'] = $this->request->post['payment_securetrading_ws_status']; + } else { + $data['payment_securetrading_ws_status'] = $this->config->get('payment_securetrading_ws_status'); + } + + if (isset($this->request->post['payment_securetrading_ws_sort_order'])) { + $data['payment_securetrading_ws_sort_order'] = $this->request->post['payment_securetrading_ws_sort_order']; + } else { + $data['payment_securetrading_ws_sort_order'] = $this->config->get('payment_securetrading_ws_sort_order'); + } + + if (isset($this->request->post['payment_securetrading_ws_total'])) { + $data['payment_securetrading_ws_total'] = $this->request->post['payment_securetrading_ws_total']; + } else { + $data['payment_securetrading_ws_total'] = $this->config->get('payment_securetrading_ws_total'); + } + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['site_reference'])) { + $data['error_site_reference'] = $this->error['site_reference']; + } else { + $data['error_site_reference'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['cards_accepted'])) { + $data['error_cards_accepted'] = $this->error['cards_accepted']; + } else { + $data['error_cards_accepted'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/securetrading_ws', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['cards'] = array( + 'AMEX' => 'American Express', + 'VISA' => 'Visa', + 'DELTA' => 'Visa Debit', + 'ELECTRON' => 'Visa Electron', + 'PURCHASING' => 'Visa Purchasing', + 'VPAY' => 'V Pay', + 'MASTERCARD' => 'MasterCard', + 'MASTERCARDDEBIT' => 'MasterCard Debit', + 'MAESTRO' => 'Maestro', + 'PAYPAL' => 'PayPal', + ); + + $data['settlement_statuses'] = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_pending_settlement_manually_overriden'), + '2' => $this->language->get('text_pending_suspended'), + '100' => $this->language->get('text_pending_settled'), + ); + + $data['action'] = $this->url->link('extension/payment/securetrading_ws', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['myst_status'] = !empty($data['securetrading_ws_csv_username']) && !empty($data['securetrading_ws_csv_password']); + $data['hours'] = array(); + + for ($i = 0; $i < 24; $i++) { + $data['hours'][] = str_pad($i, 2, '0', STR_PAD_LEFT); + } + + $data['minutes'] = array(); + + for ($i = 0; $i < 60; $i++) { + $data['minutes'][] = str_pad($i, 2, '0', STR_PAD_LEFT); + } + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/securetrading_ws', $data)); + } + + public function install() { + $this->load->model('extension/payment/securetrading_ws'); + $this->model_extension_payment_securetrading_ws->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/securetrading_ws'); + $this->model_extension_payment_securetrading_ws->uninstall(); + } + + public function downloadTransactions() { + $this->load->model('extension/payment/securetrading_ws'); + $this->load->language('extension/payment/securetrading_ws'); + + $csv_data = $this->request->post; + $csv_data['detail'] = true; + + $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data); + + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="' . $this->language->get('text_transactions') . '.csv"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . strlen($response)); + + if (ob_get_level()) { + ob_end_clean(); + } + + echo $response; + exit(); + } + + public function showTransactions() { + $this->load->model('extension/payment/securetrading_ws'); + $this->load->language('extension/payment/securetrading_ws'); + + $csv_data = $this->request->post; + $csv_data['detail'] = false; + + $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data); + + $data['transactions'] = array(); + + $status_mapping = array( + '0' => $this->language->get('text_ok'), + '70000' => $this->language->get('text_denied'), + ); + + $settle_status_mapping = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_manual_settlement'), + '2' => $this->language->get('text_suspended'), + '3' => $this->language->get('text_cancelled'), + '10' => $this->language->get('text_settling'), + '100' => $this->language->get('text_settled'), + ); + + if ($response) { + $lines = array_filter(explode("\n", $response)); + + $csv = array(); + $keys = str_getcsv($lines[0]); + + for ($i = 1; $i < count($lines); $i++) { + $csv[] = array_combine($keys, str_getcsv($lines[$i])); + } + + foreach ($csv as $row) { + $data['transactions'][] = array( + 'order_id' => $row['orderreference'], + 'order_href' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $row['orderreference'], true), + 'transaction_reference' => $row['transactionreference'], + 'customer' => $row['billingfirstname'] . ' ' . $row['billinglastname'], + 'total' => $row['mainamount'], + 'currency' => $row['currencyiso3a'], + 'settle_status' => $settle_status_mapping[$row['settlestatus']], + 'status' => $status_mapping[$row['errorcode']], + 'type' => $row['requesttypedescription'], + 'payment_type' => $row['paymenttypedescription'], + ); + } + } + + return $this->load->view('extension/payment/securetrading_ws_transactions', $data); + } + + public function order() { + + if ($this->config->get('payment_securetrading_ws_status')) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->get['order_id']); + + if (!empty($securetrading_ws_order)) { + $this->load->language('extension/payment/securetrading_ws'); + + $securetrading_ws_order['total_released'] = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + $securetrading_ws_order['total_formatted'] = $this->currency->format($securetrading_ws_order['total'], $securetrading_ws_order['currency_code'], false, false); + $securetrading_ws_order['total_released_formatted'] = $this->currency->format($securetrading_ws_order['total_released'], $securetrading_ws_order['currency_code'], false, false); + + $data['securetrading_ws_order'] = $securetrading_ws_order; + + $data['auto_settle'] = $securetrading_ws_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/securetrading_ws_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_securetrading_ws->void($this->request->post['order_id']); + + $this->model_extension_payment_securetrading_ws->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response !== false) { + $response_xml = simplexml_load_string($void_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['msg'] = (string)$response_xml->response->error->message; + $json['error'] = true; + } else { + + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'reversed', 0.00); + $this->model_extension_payment_securetrading_ws->updateVoidStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + + $this->data = array( + 'order_status_id' => $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id'), + 'notify' => false, + 'comment' => '', + ); + + $this->load->model('sale/order'); + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data); + + $json['msg'] = $this->language->get('text_authorisation_reversed'); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } + } else { + $json['msg'] = $this->language->get('error_connection'); + $json['error'] = true; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + $amount = number_format($this->request->post['amount'], 2); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_securetrading_ws->release($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_ws->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response !== false) { + $response_xml = simplexml_load_string($release_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } else { + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'payment', $amount); + + $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + if ($total_released >= $securetrading_ws_order['total'] || $securetrading_ws_order['settle_type'] == 100) { + $this->model_extension_payment_securetrading_ws->updateReleaseStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('securetrading_ws_order_status_success_settled_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (double)$total_released; + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $amount = number_format($this->request->post['amount'], 2); + + $rebate_response = $this->model_extension_payment_securetrading_ws->rebate($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_ws->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response !== false) { + $response_xml = simplexml_load_string($rebate_response); + + $error_code = (string)$response_xml->response->error->code; + + if ($error_code == '0') { + + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'rebate', $amount * -1); + + $total_rebated = $this->model_extension_payment_securetrading_ws->getTotalRebated($securetrading_ws_order['securetrading_ws_order_id']); + $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + if ($total_released <= 0 && $securetrading_ws_order['release_status'] == 1) { + $json['status'] = 1; + $json['message'] = $this->language->get('text_refund_issued'); + + $this->model_extension_payment_securetrading_ws->updateRebateStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount * -1; + $json['data']['total_released'] = (double)$total_released; + $json['data']['total_rebated'] = (double)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } + } else { + $json['status'] = 0; + $json['message'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_securetrading_ws_site_reference']) { + $this->error['site_reference'] = $this->language->get('error_site_reference'); + } + + if (!$this->request->post['payment_securetrading_ws_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_securetrading_ws_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (empty($this->request->post['payment_securetrading_ws_cards_accepted'])) { + $this->error['cards_accepted'] = $this->language->get('error_cards_accepted'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/skrill.php b/public/admin/controller/extension/payment/skrill.php new file mode 100644 index 0000000..f53b107 --- /dev/null +++ b/public/admin/controller/extension/payment/skrill.php @@ -0,0 +1,157 @@ +<?php +class ControllerExtensionPaymentSkrill extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/skrill'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_skrill', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/skrill', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/skrill', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_skrill_email'])) { + $data['payment_skrill_email'] = $this->request->post['payment_skrill_email']; + } else { + $data['payment_skrill_email'] = $this->config->get('payment_skrill_email'); + } + + if (isset($this->request->post['payment_skrill_secret'])) { + $data['payment_skrill_secret'] = $this->request->post['payment_skrill_secret']; + } else { + $data['payment_skrill_secret'] = $this->config->get('payment_skrill_secret'); + } + + if (isset($this->request->post['payment_skrill_total'])) { + $data['payment_skrill_total'] = $this->request->post['payment_skrill_total']; + } else { + $data['payment_skrill_total'] = $this->config->get('payment_skrill_total'); + } + + if (isset($this->request->post['payment_skrill_order_status_id'])) { + $data['payment_skrill_order_status_id'] = $this->request->post['payment_skrill_order_status_id']; + } else { + $data['payment_skrill_order_status_id'] = $this->config->get('payment_skrill_order_status_id'); + } + + if (isset($this->request->post['payment_skrill_pending_status_id'])) { + $data['payment_skrill_pending_status_id'] = $this->request->post['payment_skrill_pending_status_id']; + } else { + $data['payment_skrill_pending_status_id'] = $this->config->get('payment_skrill_pending_status_id'); + } + + if (isset($this->request->post['payment_skrill_canceled_status_id'])) { + $data['payment_skrill_canceled_status_id'] = $this->request->post['payment_skrill_canceled_status_id']; + } else { + $data['payment_skrill_canceled_status_id'] = $this->config->get('payment_skrill_canceled_status_id'); + } + + if (isset($this->request->post['payment_skrill_failed_status_id'])) { + $data['payment_skrill_failed_status_id'] = $this->request->post['payment_skrill_failed_status_id']; + } else { + $data['payment_skrill_failed_status_id'] = $this->config->get('payment_skrill_failed_status_id'); + } + + if (isset($this->request->post['payment_skrill_chargeback_status_id'])) { + $data['payment_skrill_chargeback_status_id'] = $this->request->post['payment_skrill_chargeback_status_id']; + } else { + $data['payment_skrill_chargeback_status_id'] = $this->config->get('payment_skrill_chargeback_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_skrill_geo_zone_id'])) { + $data['payment_skrill_geo_zone_id'] = $this->request->post['payment_skrill_geo_zone_id']; + } else { + $data['payment_skrill_geo_zone_id'] = $this->config->get('payment_skrill_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_skrill_status'])) { + $data['payment_skrill_status'] = $this->request->post['payment_skrill_status']; + } else { + $data['payment_skrill_status'] = $this->config->get('payment_skrill_status'); + } + + if (isset($this->request->post['payment_skrill_sort_order'])) { + $data['payment_skrill_sort_order'] = $this->request->post['payment_skrill_sort_order']; + } else { + $data['payment_skrill_sort_order'] = $this->config->get('payment_skrill_sort_order'); + } + + if (isset($this->request->post['payment_skrill_rid'])) { + $data['payment_skrill_rid'] = $this->request->post['payment_skrill_rid']; + } else { + $data['payment_skrill_rid'] = $this->config->get('payment_skrill_rid'); + } + + if (isset($this->request->post['payment_skrill_custnote'])) { + $data['payment_skrill_custnote'] = $this->request->post['payment_skrill_custnote']; + } else { + $data['payment_skrill_custnote'] = $this->config->get('payment_skrill_custnote'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/skrill', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/skrill')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_skrill_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/squareup.php b/public/admin/controller/extension/payment/squareup.php new file mode 100644 index 0000000..1ab2916 --- /dev/null +++ b/public/admin/controller/extension/payment/squareup.php @@ -0,0 +1,1079 @@ +<?php + +class ControllerExtensionPaymentSquareup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + if ($this->request->server['HTTPS']) { + $server = HTTPS_SERVER; + } else { + $server = HTTP_SERVER; + } + + $previous_setting = $this->model_setting_setting->getSetting('payment_squareup'); + + try { + if ($this->config->get('payment_squareup_access_token')) { + if (!$this->squareup->verifyToken($this->config->get('payment_squareup_access_token'))) { + unset($previous_setting['payment_squareup_merchant_id']); + unset($previous_setting['payment_squareup_merchant_name']); + unset($previous_setting['payment_squareup_access_token']); + unset($previous_setting['payment_squareup_access_token_expires']); + unset($previous_setting['payment_squareup_locations']); + unset($previous_setting['payment_squareup_sandbox_locations']); + + $this->config->set('payment_squareup_merchant_id', null); + } else { + if (!$this->config->get('payment_squareup_locations')) { + $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_access_token'), $first_location_id); + $previous_setting['payment_squareup_location_id'] = $first_location_id; + } + } + } + + if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) { + $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id); + $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id; + } + + $this->model_setting_setting->editSetting('payment_squareup', $previous_setting); + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_location_error'), $e->getMessage()) + )); + } + + $previous_config = new Config(); + + foreach ($previous_setting as $key => $value) { + $previous_config->set($key, $value); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { + $this->model_setting_setting->editSetting('payment_squareup', array_merge($previous_setting, $this->request->post)); + + $this->session->data['success'] = $this->language->get('text_success'); + + if (isset($this->request->get['save_and_auth'])) { + $this->response->redirect($this->squareup->authLink($this->request->post['payment_squareup_client_id'])); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data['error_status'] = $this->getValidationError('status'); + $data['error_display_name'] = $this->getValidationError('display_name'); + $data['error_client_id'] = $this->getValidationError('client_id'); + $data['error_client_secret'] = $this->getValidationError('client_secret'); + $data['error_delay_capture'] = $this->getValidationError('delay_capture'); + $data['error_sandbox_client_id'] = $this->getValidationError('sandbox_client_id'); + $data['error_sandbox_token'] = $this->getValidationError('sandbox_token'); + $data['error_location'] = $this->getValidationError('location'); + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + $data['payment_squareup_status'] = $this->getSettingValue('payment_squareup_status'); + $data['payment_squareup_status_authorized'] = $this->getSettingValue('payment_squareup_status_authorized'); + $data['payment_squareup_status_captured'] = $this->getSettingValue('payment_squareup_status_captured'); + $data['payment_squareup_status_voided'] = $this->getSettingValue('payment_squareup_status_voided'); + $data['payment_squareup_status_failed'] = $this->getSettingValue('payment_squareup_status_failed'); + $data['payment_squareup_display_name'] = $this->getSettingValue('payment_squareup_display_name'); + $data['payment_squareup_client_id'] = $this->getSettingValue('payment_squareup_client_id'); + $data['payment_squareup_client_secret'] = $this->getSettingValue('payment_squareup_client_secret'); + $data['payment_squareup_enable_sandbox'] = $this->getSettingValue('payment_squareup_enable_sandbox'); + $data['payment_squareup_debug'] = $this->getSettingValue('payment_squareup_debug'); + $data['payment_squareup_sort_order'] = $this->getSettingValue('payment_squareup_sort_order'); + $data['payment_squareup_total'] = $this->getSettingValue('payment_squareup_total'); + $data['payment_squareup_geo_zone_id'] = $this->getSettingValue('payment_squareup_geo_zone_id'); + $data['payment_squareup_sandbox_client_id'] = $this->getSettingValue('payment_squareup_sandbox_client_id'); + $data['payment_squareup_sandbox_token'] = $this->getSettingValue('payment_squareup_sandbox_token'); + $data['payment_squareup_locations'] = $this->getSettingValue('payment_squareup_locations', $previous_config->get('payment_squareup_locations')); + $data['payment_squareup_location_id'] = $this->getSettingValue('payment_squareup_location_id'); + $data['payment_squareup_sandbox_locations'] = $this->getSettingValue('payment_squareup_sandbox_locations', $previous_config->get('payment_squareup_sandbox_locations')); + $data['payment_squareup_sandbox_location_id'] = $this->getSettingValue('payment_squareup_sandbox_location_id'); + $data['payment_squareup_delay_capture'] = $this->getSettingValue('payment_squareup_delay_capture'); + $data['payment_squareup_recurring_status'] = $this->getSettingValue('payment_squareup_recurring_status'); + $data['payment_squareup_cron_email_status'] = $this->getSettingValue('payment_squareup_cron_email_status'); + $data['payment_squareup_cron_email'] = $this->getSettingValue('payment_squareup_cron_email', $this->config->get('config_email')); + $data['payment_squareup_cron_token'] = $this->getSettingValue('payment_squareup_cron_token'); + $data['payment_squareup_cron_acknowledge'] = $this->getSettingValue('payment_squareup_cron_acknowledge', null, true); + $data['payment_squareup_notify_recurring_success'] = $this->getSettingValue('payment_squareup_notify_recurring_success'); + $data['payment_squareup_notify_recurring_fail'] = $this->getSettingValue('payment_squareup_notify_recurring_fail'); + $data['payment_squareup_merchant_id'] = $this->getSettingValue('payment_squareup_merchant_id', $previous_config->get('payment_squareup_merchant_id')); + $data['payment_squareup_merchant_name'] = $this->getSettingValue('payment_squareup_merchant_name', $previous_config->get('payment_squareup_merchant_name')); + + if ($previous_config->get('payment_squareup_access_token') && $previous_config->get('payment_squareup_access_token_expires')) { + $expiration_time = date_create_from_format('Y-m-d\TH:i:s\Z', $previous_config->get('payment_squareup_access_token_expires')); + $now = date_create(); + + $delta = $expiration_time->getTimestamp() - $now->getTimestamp(); + $expiration_date_formatted = $expiration_time->format('l, F jS, Y h:i:s A, e'); + + if ($delta < 0) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_expired'), $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true)) + )); + } else if ($delta < (5 * 24 * 60 * 60)) { // token is valid, just about to expire + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_expiry_warning'), $expiration_date_formatted, $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true)) + )); + } + + $data['access_token_expires_time'] = $expiration_date_formatted; + } else if ($previous_config->get('payment_squareup_client_id')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_revoked'), $this->squareup->authLink($previous_config->get('payment_squareup_client_id'))) + )); + + $data['access_token_expires_time'] = $this->language->get('text_na'); + } + + if ($previous_config->get('payment_squareup_client_id')) { + $data['payment_squareup_auth_link'] = $this->squareup->authLink($previous_config->get('payment_squareup_client_id')); + } else { + $data['payment_squareup_auth_link'] = null; + } + + $data['payment_squareup_redirect_uri'] = str_replace('&', '&', $this->url->link('extension/payment/squareup/oauth_callback', '', true)); + $data['payment_squareup_refresh_link'] = $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->config->get('payment_squareup_enable_sandbox')) { + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_sandbox_enabled') + )); + } + + if (isset($this->error['warning'])) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->error['warning'] + )); + } + + // Insert success message from the session + if (isset($this->session->data['success'])) { + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->session->data['success'] + )); + + unset($this->session->data['success']); + } + + if ($this->request->server['HTTPS']) { + // Push the SSL reminder alert + $this->pushAlert(array( + 'type' => 'info', + 'icon' => 'lock', + 'text' => $this->language->get('text_notification_ssl') + )); + } else { + // Push the SSL reminder alert + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_no_ssl') + )); + } + + $tabs = array( + 'tab-transaction', + 'tab-setting', + 'tab-recurring', + 'tab-cron' + ); + + if (isset($this->request->get['tab']) && in_array($this->request->get['tab'], $tabs)) { + $data['tab'] = $this->request->get['tab']; + } else if (isset($this->error['cron_email']) || isset($this->error['cron_acknowledge'])) { + $data['tab'] = 'tab-cron'; + } else if ($this->error) { + $data['tab'] = 'tab-setting'; + } else { + $data['tab'] = $tabs[1]; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + $data['action_save_auth'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&save_and_auth=1', true)); + $data['cancel'] = html_entity_decode($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&page={PAGE}', true)); + + $this->load->model('localisation/language'); + $data['languages'] = array(); + foreach ($this->model_localisation_language->getLanguages() as $language) { + $data['languages'][] = array( + 'language_id' => $language['language_id'], + 'name' => $language['name'] . ($language['code'] == $this->config->get('config_language') ? $this->language->get('text_default') : ''), + 'image' => 'language/' . $language['code'] . '/'. $language['code'] . '.png' + ); + } + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['payment_squareup_cron_command'] = PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' ' . DIR_SYSTEM . 'library/squareup/cron.php ' . parse_url($server, PHP_URL_HOST) . ' 443 > /dev/null 2> /dev/null'; + + if (!$this->config->get('payment_squareup_cron_token')) { + $data['payment_squareup_cron_token'] = md5(mt_rand()); + } + + $data['payment_squareup_cron_url'] = 'https://' . parse_url($server, PHP_URL_HOST) . dirname(parse_url($server, PHP_URL_PATH)) . '/index.php?route=extension/recurring/squareup/recurring&cron_token={CRON_TOKEN}'; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['alerts'] = $this->pullAlerts(); + + $this->clearAlerts(); + + $this->response->setOutput($this->load->view('extension/payment/squareup', $data)); + } + + public function transaction_info() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + $this->load->library('squareup'); + + if (isset($this->request->get['squareup_transaction_id'])) { + $squareup_transaction_id = $this->request->get['squareup_transaction_id']; + } else { + $squareup_transaction_id = 0; + } + + $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id); + + if (empty($transaction_info)) { + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle(sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id'])); + + $data['alerts'] = $this->pullAlerts(); + + $this->clearAlerts(); + + $data['text_edit'] = sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id']); + + $amount = $this->currency->format($transaction_info['transaction_amount'], $transaction_info['transaction_currency']); + + $data['confirm_capture'] = sprintf($this->language->get('text_confirm_capture'), $amount); + $data['confirm_void'] = sprintf($this->language->get('text_confirm_void'), $amount); + $data['confirm_refund'] = $this->language->get('text_confirm_refund'); + $data['insert_amount'] = sprintf($this->language->get('text_insert_amount'), $amount, $transaction_info['transaction_currency']); + $data['text_loading'] = $this->language->get('text_loading_short'); + + $data['billing_address_company'] = $transaction_info['billing_address_company']; + $data['billing_address_street'] = $transaction_info['billing_address_street_1'] . ' ' . $transaction_info['billing_address_street_2']; + $data['billing_address_city'] = $transaction_info['billing_address_city']; + $data['billing_address_postcode'] = $transaction_info['billing_address_postcode']; + $data['billing_address_province'] = $transaction_info['billing_address_province']; + $data['billing_address_country'] = $transaction_info['billing_address_country']; + + $data['transaction_id'] = $transaction_info['transaction_id']; + $data['merchant'] = $transaction_info['merchant_id']; + $data['order_id'] = $transaction_info['order_id']; + $data['type'] = $transaction_info['transaction_type']; + $data['amount'] = $amount; + $data['currency'] = $transaction_info['transaction_currency']; + $data['browser'] = $transaction_info['device_browser']; + $data['ip'] = $transaction_info['device_ip']; + $data['date_created'] = date($this->language->get('datetime_format'), strtotime($transaction_info['created_at'])); + + $data['cancel'] = $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&tab=tab-transaction', true); + + $data['url_order'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction_info['order_id'], true); + $data['url_void'] = $this->url->link('extension/payment/squareup' . '/void', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_capture'] = $this->url->link('extension/payment/squareup' . '/capture', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_refund'] = $this->url->link('extension/payment/squareup' . '/refund', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_transaction'] = sprintf( + Squareup::VIEW_TRANSACTION_URL, + $transaction_info['transaction_id'], + $transaction_info['location_id'] + ); + + $data['is_authorized'] = in_array($transaction_info['transaction_type'], array('AUTHORIZED')); + $data['is_captured'] = in_array($transaction_info['transaction_type'], array('CAPTURED')); + + $data['has_refunds'] = (bool)$transaction_info['is_refunded']; + + if ($data['has_refunds']) { + $refunds = @json_decode($transaction_info['refunds'], true); + + $data['refunds'] = array(); + + $data['text_refunds'] = sprintf($this->language->get('text_refunds'), count($refunds)); + + foreach ($refunds as $refund) { + $amount = $this->currency->format( + $this->squareup->standardDenomination( + $refund['amount_money']['amount'], + $refund['amount_money']['currency'] + ), + $refund['amount_money']['currency'] + ); + + $fee = $this->currency->format( + $this->squareup->standardDenomination( + $refund['processing_fee_money']['amount'], + $refund['processing_fee_money']['currency'] + ), + $refund['processing_fee_money']['currency'] + ); + + $data['refunds'][] = array( + 'date_created' => date($this->language->get('datetime_format'), strtotime($refund['created_at'])), + 'reason' => $refund['reason'], + 'status' => $refund['status'], + 'amount' => $amount, + 'fee' => $fee + ); + } + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => sprintf($this->language->get('heading_title_transaction'), $transaction_info['squareup_transaction_id']), + 'href' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $squareup_transaction_id, true) + ); + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/squareup_transaction_info', $data)); + } + + public function transactions() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + if (isset($this->request->get['page'])) { + $page = (int)$this->request->get['page']; + } else { + $page = 1; + } + + $result = array( + 'transactions' => array(), + 'pagination' => '' + ); + + $filter_data = array( + 'start' => ($page - 1) * (int)$this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + if (isset($this->request->get['order_id'])) { + $filter_data['order_id'] = $this->request->get['order_id']; + } + + $transactions_total = $this->model_extension_payment_squareup->getTotalTransactions($filter_data); + $transactions = $this->model_extension_payment_squareup->getTransactions($filter_data); + + $this->load->model('sale/order'); + + foreach ($transactions as $transaction) { + $amount = $this->currency->format($transaction['transaction_amount'], $transaction['transaction_currency']); + + $order_info = $this->model_sale_order->getOrder($transaction['order_id']); + + $result['transactions'][] = array( + 'squareup_transaction_id' => $transaction['squareup_transaction_id'], + 'transaction_id' => $transaction['transaction_id'], + 'url_order' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true), + 'url_void' => $this->url->link('extension/payment/squareup/void', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'url_capture' => $this->url->link('extension/payment/squareup/capture', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'url_refund' => $this->url->link('extension/payment/squareup/refund', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'confirm_capture' => sprintf($this->language->get('text_confirm_capture'), $amount), + 'confirm_void' => sprintf($this->language->get('text_confirm_void'), $amount), + 'confirm_refund' => $this->language->get('text_confirm_refund'), + 'insert_amount' => sprintf($this->language->get('text_insert_amount'), $amount, $transaction['transaction_currency']), + 'order_id' => $transaction['order_id'], + 'type' => $transaction['transaction_type'], + 'num_refunds' => count(@json_decode($transaction['refunds'], true)), + 'amount' => $amount, + 'customer' => $order_info['firstname'] . ' ' . $order_info['lastname'], + 'ip' => $transaction['device_ip'], + 'date_created' => date($this->language->get('datetime_format'), strtotime($transaction['created_at'])), + 'url_info' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true) + ); + } + + $pagination = new Pagination(); + $pagination->total = $transactions_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = '{page}'; + + $result['pagination'] = $pagination->render(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + public function refresh_token() { + $this->load->language('extension/payment/squareup'); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_permission') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + try { + $response = $this->squareup->refreshToken(); + + if (!isset($response['access_token']) || !isset($response['token_type']) || !isset($response['expires_at']) || !isset($response['merchant_id']) || + $response['merchant_id'] != $this->config->get('payment_squareup_merchant_id')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_refresh_access_token') + )); + } else { + $settings = $this->model_setting_setting->getSetting('payment_squareup'); + + $settings['payment_squareup_access_token'] = $response['access_token']; + $settings['payment_squareup_access_token_expires'] = $response['expires_at']; + + $this->model_setting_setting->editSetting('payment_squareup', $settings); + + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_refresh_access_token_success') + )); + } + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('error_token'), $e->getMessage()) + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function oauth_callback() { + $this->load->language('extension/payment/squareup'); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_permission') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + if (isset($this->request->get['error']) || isset($this->request->get['error_description'])) { + // auth error + if ($this->request->get['error'] == 'access_denied' && $this->request->get['error_description'] == 'user_denied') { + // user rejected giving auth permissions to his store + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_user_rejected_connect_attempt') + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + // verify parameters for the redirect from Square (against random url crawling) + if (!isset($this->request->get['state']) || !isset($this->request->get['code']) || !isset($this->request->get['response_type'])) { + // missing or wrong info + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_possible_xss') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + // verify the state (against cross site requests) + if (!isset($this->session->data['payment_squareup_oauth_state']) || $this->session->data['payment_squareup_oauth_state'] != $this->request->get['state']) { + // state mismatch + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_possible_xss') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + try { + $token = $this->squareup->exchangeCodeForAccessToken($this->request->get['code']); + + $previous_setting = $this->model_setting_setting->getSetting('payment_squareup'); + + $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($token['access_token'], $first_location_id); + + if ( + !isset($previous_setting['payment_squareup_location_id']) || + (isset($previous_setting['payment_squareup_location_id']) && !in_array( + $previous_setting['payment_squareup_location_id'], + array_map( + function($location) { + return $location['id']; + }, + $previous_setting['payment_squareup_locations'] + ) + )) + ) { + $previous_setting['payment_squareup_location_id'] = $first_location_id; + } + + if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) { + $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id); + $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id; + } + + $previous_setting['payment_squareup_merchant_id'] = $token['merchant_id']; + $previous_setting['payment_squareup_merchant_name'] = ''; // only available in v1 of the API, not populated for now + $previous_setting['payment_squareup_access_token'] = $token['access_token']; + $previous_setting['payment_squareup_access_token_expires'] = $token['expires_at']; + + $this->model_setting_setting->editSetting('payment_squareup', $previous_setting); + + unset($this->session->data['payment_squareup_oauth_state']); + unset($this->session->data['payment_squareup_oauth_redirect']); + + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_refresh_access_token_success') + )); + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('error_token'), $e->getMessage()) + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function capture() { + $this->transactionAction(function($transaction_info, &$json) { + $updated_transaction = $this->squareup->captureTransaction($transaction_info['location_id'], $transaction_info['transaction_id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status), + 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)), + ); + + $json['success'] = $this->language->get('text_success_capture'); + }); + } + + public function void() { + $this->transactionAction(function($transaction_info, &$json) { + $updated_transaction = $this->squareup->voidTransaction($transaction_info['location_id'], $transaction_info['transaction_id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status), + 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)), + ); + + $json['success'] = $this->language->get('text_success_void'); + }); + } + + public function refund() { + $this->transactionAction(function($transaction_info, &$json) { + if (!empty($this->request->post['reason'])) { + $reason = $this->request->post['reason']; + } else { + $reason = $this->language->get('text_no_reason_provided'); + } + + if (!empty($this->request->post['amount'])) { + $amount = preg_replace('~[^0-9\.\,]~', '', $this->request->post['amount']); + + if (strpos($amount, ',') !== FALSE && strpos($amount, '.') !== FALSE) { + $amount = (float)str_replace(',', '', $amount); + } else if (strpos($amount, ',') !== FALSE && strpos($amount, '.') === FALSE) { + $amount = (float)str_replace(',', '.', $amount); + } else { + $amount = (float)$amount; + } + } else { + $amount = 0; + } + + $currency = $transaction_info['transaction_currency']; + $tenders = @json_decode($transaction_info['tenders'], true); + + $updated_transaction = $this->squareup->refundTransaction($transaction_info['location_id'], $transaction_info['transaction_id'], $reason, $amount, $currency, $tenders[0]['id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $refunds = array(); + + if (!empty($updated_transaction['refunds'])) { + $refunds = $updated_transaction['refunds']; + } + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status, $refunds); + + $last_refund = array_pop($refunds); + + if ($last_refund) { + $refunded_amount = $this->currency->format( + $this->squareup->standardDenomination( + $last_refund['amount_money']['amount'], + $last_refund['amount_money']['currency'] + ), + $last_refund['amount_money']['currency'] + ); + + $comment = sprintf($this->language->get('text_refunded_amount'), $refunded_amount, $last_refund['status'], $last_refund['reason']); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id']), + 'comment' => $comment, + ); + + $json['success'] = $this->language->get('text_success_refund'); + } else { + $json['error'] = $this->language->get('error_no_refund'); + } + }); + } + + public function order() { + $this->load->language('extension/payment/squareup'); + + $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'] . '&page={PAGE}', true)); + $data['user_token'] = $this->session->data['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + return $this->load->view('extension/payment/squareup_order', $data); + } + + public function install() { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->createTables(); + } + + public function uninstall() { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->dropTables(); + } + + public function recurringButtons() { + if (!$this->user->hasPermission('modify', 'sale/recurring')) { + return; + } + + $this->load->model('extension/payment/squareup'); + + $this->load->language('extension/payment/squareup'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + $data['button_text'] = $this->language->get('button_cancel_recurring'); + + if ($recurring_info['status'] == ModelExtensionPaymentSquareup::RECURRING_ACTIVE) { + $data['order_recurring_id'] = $order_recurring_id; + } else { + $data['order_recurring_id'] = ''; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($recurring_info['order_id']); + + $data['order_id'] = $recurring_info['order_id']; + $data['store_id'] = $order_info['store_id']; + $data['order_status_id'] = $order_info['order_status_id']; + $data['comment'] = $this->language->get('text_order_history_cancel'); + $data['notify'] = 1; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['cancel'] = html_entity_decode($this->url->link('extension/payment/squareup/recurringCancel', 'order_recurring_id=' . $order_recurring_id . '&user_token=' . $this->session->data['user_token'], true)); + + return $this->load->view('extension/payment/squareup_recurring_buttons', $data); + } + + public function recurringCancel() { + $this->load->language('extension/payment/squareup'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/recurring')) { + $json['error'] = $this->language->get('error_permission_recurring'); + } else { + $this->load->model('sale/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + if ($recurring_info) { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->editOrderRecurringStatus($order_recurring_id, ModelExtensionPaymentSquareup::RECURRING_CANCELLED); + + $json['success'] = $this->language->get('text_canceled_success'); + + } else { + $json['error'] = $this->language->get('error_not_found'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['payment_squareup_client_id']) || strlen($this->request->post['payment_squareup_client_id']) > 32) { + $this->error['client_id'] = $this->language->get('error_client_id'); + } + + if (empty($this->request->post['payment_squareup_client_secret']) || strlen($this->request->post['payment_squareup_client_secret']) > 50) { + $this->error['client_secret'] = $this->language->get('error_client_secret'); + } + + if (!empty($this->request->post['payment_squareup_enable_sandbox'])) { + if (empty($this->request->post['payment_squareup_sandbox_client_id']) || strlen($this->request->post['payment_squareup_sandbox_client_id']) > 42) { + $this->error['sandbox_client_id'] = $this->language->get('error_sandbox_client_id'); + } + + if (empty($this->request->post['payment_squareup_sandbox_token']) || strlen($this->request->post['payment_squareup_sandbox_token']) > 42) { + $this->error['sandbox_token'] = $this->language->get('error_sandbox_token'); + } + + if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_sandbox_locations')) { + $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning'); + } + + if ($this->config->get('payment_squareup_sandbox_locations') && isset($this->request->post['payment_squareup_sandbox_location_id']) && !in_array($this->request->post['payment_squareup_sandbox_location_id'], array_map(function($location) { + return $location['id']; + }, $this->config->get('payment_squareup_sandbox_locations')))) { + $this->error['location'] = $this->language->get('error_no_location_selected'); + } + } else { + if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_locations')) { + $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning'); + } + + if ($this->config->get('payment_squareup_locations') && isset($this->request->post['payment_squareup_location_id']) && !in_array($this->request->post['payment_squareup_location_id'], array_map(function($location) { + return $location['id']; + }, $this->config->get('payment_squareup_locations')))) { + $this->error['location'] = $this->language->get('error_no_location_selected'); + } + } + + if (!empty($this->request->post['payment_squareup_cron_email_status'])) { + if (!filter_var($this->request->post['payment_squareup_cron_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['cron_email'] = $this->language->get('error_invalid_email'); + } + } + + if (!isset($this->request->get['save_and_auth']) && empty($this->request->post['payment_squareup_cron_acknowledge'])) { + $this->error['cron_acknowledge'] = $this->language->get('error_cron_acknowledge'); + } + + if ($this->error && empty($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_form'); + } + + return !$this->error; + } + + protected function transactionAction($callback) { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + $this->load->library('squareup'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (isset($this->request->get['squareup_transaction_id'])) { + $squareup_transaction_id = $this->request->get['squareup_transaction_id']; + } else { + $squareup_transaction_id = 0; + } + + $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id); + + if (empty($transaction_info)) { + $json['error'] = $this->language->get('error_transaction_missing'); + } else { + try { + $callback($transaction_info, $json); + } catch (\Squareup\Exception $e) { + $json['error'] = $e->getMessage(); + } + } + + if (isset($this->request->get['preserve_alert'])) { + if (!empty($json['error'])) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $json['error'] + )); + } + + if (!empty($json['success'])) { + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $json['success'] + )); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function pushAlert($alert) { + $this->session->data['payment_squareup_alerts'][] = $alert; + } + + protected function pullAlerts() { + if (isset($this->session->data['payment_squareup_alerts'])) { + return $this->session->data['payment_squareup_alerts']; + } else { + return array(); + } + } + + protected function clearAlerts() { + unset($this->session->data['payment_squareup_alerts']); + } + + protected function getSettingValue($key, $default = null, $checkbox = false) { + if ($checkbox) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post[$key])) { + return $default; + } else { + return $this->config->get($key); + } + } + + if (isset($this->request->post[$key])) { + return $this->request->post[$key]; + } else if ($this->config->has($key)) { + return $this->config->get($key); + } else { + return $default; + } + } + + protected function getValidationError($key) { + if (isset($this->error[$key])) { + return $this->error[$key]; + } else { + return ''; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/twocheckout.php b/public/admin/controller/extension/payment/twocheckout.php new file mode 100644 index 0000000..38ff762 --- /dev/null +++ b/public/admin/controller/extension/payment/twocheckout.php @@ -0,0 +1,143 @@ +<?php +class ControllerExtensionPaymentTwoCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/twocheckout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_twocheckout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/twocheckout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/twocheckout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_twocheckout_account'])) { + $data['payment_twocheckout_account'] = $this->request->post['payment_twocheckout_account']; + } else { + $data['payment_twocheckout_account'] = $this->config->get('payment_twocheckout_account'); + } + + if (isset($this->request->post['payment_twocheckout_secret'])) { + $data['payment_twocheckout_secret'] = $this->request->post['payment_twocheckout_secret']; + } else { + $data['payment_twocheckout_secret'] = $this->config->get('payment_twocheckout_secret'); + } + + if (isset($this->request->post['payment_twocheckout_display'])) { + $data['payment_twocheckout_display'] = $this->request->post['payment_twocheckout_display']; + } else { + $data['payment_twocheckout_display'] = $this->config->get('payment_twocheckout_display'); + } + + if (isset($this->request->post['payment_twocheckout_test'])) { + $data['payment_twocheckout_test'] = $this->request->post['payment_twocheckout_test']; + } else { + $data['payment_twocheckout_test'] = $this->config->get('payment_twocheckout_test'); + } + + if (isset($this->request->post['payment_twocheckout_total'])) { + $data['payment_twocheckout_total'] = $this->request->post['payment_twocheckout_total']; + } else { + $data['payment_twocheckout_total'] = $this->config->get('payment_twocheckout_total'); + } + + if (isset($this->request->post['payment_twocheckout_order_status_id'])) { + $data['payment_twocheckout_order_status_id'] = $this->request->post['payment_twocheckout_order_status_id']; + } else { + $data['payment_twocheckout_order_status_id'] = $this->config->get('payment_twocheckout_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_twocheckout_geo_zone_id'])) { + $data['payment_twocheckout_geo_zone_id'] = $this->request->post['payment_twocheckout_geo_zone_id']; + } else { + $data['payment_twocheckout_geo_zone_id'] = $this->config->get('payment_twocheckout_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_twocheckout_status'])) { + $data['payment_twocheckout_status'] = $this->request->post['payment_twocheckout_status']; + } else { + $data['payment_twocheckout_status'] = $this->config->get('payment_twocheckout_status'); + } + + if (isset($this->request->post['payment_twocheckout_sort_order'])) { + $data['payment_twocheckout_sort_order'] = $this->request->post['payment_twocheckout_sort_order']; + } else { + $data['payment_twocheckout_sort_order'] = $this->config->get('payment_twocheckout_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/twocheckout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/twocheckout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_twocheckout_account']) { + $this->error['account'] = $this->language->get('error_account'); + } + + if (!$this->request->post['payment_twocheckout_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/web_payment_software.php b/public/admin/controller/extension/payment/web_payment_software.php new file mode 100644 index 0000000..fa3a467 --- /dev/null +++ b/public/admin/controller/extension/payment/web_payment_software.php @@ -0,0 +1,142 @@ +<?php +class ControllerExtensionPaymentWebPaymentSoftware extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/web_payment_software'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_web_payment_software', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['login'])) { + $data['error_login'] = $this->error['login']; + } else { + $data['error_login'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/web_payment_software', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/web_payment_software', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_web_payment_software_merchant_name'])) { + $data['payment_web_payment_software_merchant_name'] = $this->request->post['payment_web_payment_software_merchant_name']; + } else { + $data['payment_web_payment_software_merchant_name'] = $this->config->get('payment_web_payment_software_merchant_name'); + } + + if (isset($this->request->post['payment_web_payment_software_merchant_key'])) { + $data['payment_web_payment_software_merchant_key'] = $this->request->post['payment_web_payment_software_merchant_key']; + } else { + $data['payment_web_payment_software_merchant_key'] = $this->config->get('payment_web_payment_software_merchant_key'); + } + + if (isset($this->request->post['payment_web_payment_software_mode'])) { + $data['payment_web_payment_software_mode'] = $this->request->post['payment_web_payment_software_mode']; + } else { + $data['payment_web_payment_software_mode'] = $this->config->get('payment_web_payment_software_mode'); + } + + if (isset($this->request->post['payment_web_payment_software_method'])) { + $data['payment_web_payment_software_method'] = $this->request->post['payment_web_payment_software_method']; + } else { + $data['payment_web_payment_software_method'] = $this->config->get('payment_web_payment_software_method'); + } + + if (isset($this->request->post['payment_web_payment_software_order_status_id'])) { + $data['payment_web_payment_software_order_status_id'] = $this->request->post['payment_web_payment_software_order_status_id']; + } else { + $data['payment_web_payment_software_order_status_id'] = $this->config->get('payment_web_payment_software_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_web_payment_software_geo_zone_id'])) { + $data['payment_web_payment_software_geo_zone_id'] = $this->request->post['payment_web_payment_software_geo_zone_id']; + } else { + $data['payment_web_payment_software_geo_zone_id'] = $this->config->get('payment_web_payment_software_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_web_payment_software_status'])) { + $data['payment_web_payment_software_status'] = $this->request->post['payment_web_payment_software_status']; + } else { + $data['payment_web_payment_software_status'] = $this->config->get('payment_web_payment_software_status'); + } + + if (isset($this->request->post['payment_web_payment_software_total'])) { + $data['payment_web_payment_software_total'] = $this->request->post['payment_web_payment_software_total']; + } else { + $data['payment_web_payment_software_total'] = $this->config->get('payment_web_payment_software_total'); + } + + if (isset($this->request->post['payment_web_payment_software_sort_order'])) { + $data['payment_web_payment_software_sort_order'] = $this->request->post['payment_web_payment_software_sort_order']; + } else { + $data['payment_web_payment_software_sort_order'] = $this->config->get('payment_web_payment_software_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/web_payment_software', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/web_payment_software')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_web_payment_software_merchant_name']) { + $this->error['login'] = $this->language->get('error_login'); + } + + if (!$this->request->post['payment_web_payment_software_merchant_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/wechat_pay.php b/public/admin/controller/extension/payment/wechat_pay.php new file mode 100644 index 0000000..754bb13 --- /dev/null +++ b/public/admin/controller/extension/payment/wechat_pay.php @@ -0,0 +1,177 @@ +<?php +/** + * @package OpenCart + * @author Meng Wenbin + * @copyright Copyright (c) 2010 - 2017, Chengdu Guangda Network Technology Co. Ltd. (https://www.opencart.cn/) + * @license https://opensource.org/licenses/GPL-3.0 + * @link https://www.opencart.cn + */ + +class ControllerExtensionPaymentWechatPay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/wechat_pay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_wechat_pay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['app_secret'])) { + $data['error_app_secret'] = $this->error['app_secret']; + } else { + $data['error_app_secret'] = ''; + } + + if (isset($this->error['mch_id'])) { + $data['error_mch_id'] = $this->error['mch_id']; + } else { + $data['error_mch_id'] = ''; + } + + if (isset($this->error['api_secret'])) { + $data['error_api_secret'] = $this->error['api_secret']; + } else { + $data['error_api_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_wechat_pay_app_id'])) { + $data['payment_wechat_pay_app_id'] = $this->request->post['payment_wechat_pay_app_id']; + } else { + $data['payment_wechat_pay_app_id'] = $this->config->get('payment_wechat_pay_app_id'); + } + + if (isset($this->request->post['payment_wechat_pay_app_secret'])) { + $data['payment_wechat_pay_app_secret'] = $this->request->post['payment_wechat_pay_app_secret']; + } else { + $data['payment_wechat_pay_app_secret'] = $this->config->get('payment_wechat_pay_app_secret'); + } + + if (isset($this->request->post['payment_wechat_pay_mch_id'])) { + $data['payment_wechat_pay_mch_id'] = $this->request->post['payment_wechat_pay_mch_id']; + } else { + $data['payment_wechat_pay_mch_id'] = $this->config->get('payment_wechat_pay_mch_id'); + } + + if (isset($this->request->post['payment_wechat_pay_api_secret'])) { + $data['payment_wechat_pay_api_secret'] = $this->request->post['payment_wechat_pay_api_secret']; + } else { + $data['payment_wechat_pay_api_secret'] = $this->config->get('payment_wechat_pay_api_secret'); + } + + if (isset($this->request->post['payment_wechat_pay_total'])) { + $data['payment_wechat_pay_total'] = $this->request->post['payment_wechat_pay_total']; + } else { + $data['payment_wechat_pay_total'] = $this->config->get('payment_wechat_pay_total'); + } + + if (isset($this->request->post['payment_wechat_pay_currency'])) { + $data['payment_wechat_pay_currency'] = $this->request->post['payment_wechat_pay_currency']; + } else { + $data['payment_wechat_pay_currency'] = $this->config->get('payment_wechat_pay_currency'); + } + + if (isset($this->request->post['payment_wechat_pay_completed_status_id'])) { + $data['payment_wechat_pay_completed_status_id'] = $this->request->post['payment_wechat_pay_completed_status_id']; + } else { + $data['payment_wechat_pay_completed_status_id'] = $this->config->get('payment_wechat_pay_completed_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_wechat_pay_geo_zone_id'])) { + $data['payment_wechat_pay_geo_zone_id'] = $this->request->post['payment_wechat_pay_geo_zone_id']; + } else { + $data['payment_wechat_pay_geo_zone_id'] = $this->config->get('payment_wechat_pay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_wechat_pay_status'])) { + $data['payment_wechat_pay_status'] = $this->request->post['payment_wechat_pay_status']; + } else { + $data['payment_wechat_pay_status'] = $this->config->get('payment_wechat_pay_status'); + } + + if (isset($this->request->post['payment_wechat_pay_sort_order'])) { + $data['payment_wechat_pay_sort_order'] = $this->request->post['payment_wechat_pay_sort_order']; + } else { + $data['payment_wechat_pay_sort_order'] = $this->config->get('payment_wechat_pay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/wechat_pay', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/wechat_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_wechat_pay_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_wechat_pay_app_secret']) { + $this->error['app_secret'] = $this->language->get('error_app_secret'); + } + + if (!$this->request->post['payment_wechat_pay_mch_id']) { + $this->error['mch_id'] = $this->language->get('error_mch_id'); + } + + if (!$this->request->post['payment_wechat_pay_api_secret']) { + $this->error['api_secret'] = $this->language->get('error_api_secret'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/worldpay.php b/public/admin/controller/extension/payment/worldpay.php new file mode 100644 index 0000000..d421bab --- /dev/null +++ b/public/admin/controller/extension/payment/worldpay.php @@ -0,0 +1,287 @@ +<?php +class ControllerExtensionPaymentWorldpay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/worldpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_worldpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['error_service_key'])) { + $data['error_service_key'] = $this->error['error_service_key']; + } else { + $data['error_service_key'] = ''; + } + + if (isset($this->error['error_client_key'])) { + $data['error_client_key'] = $this->error['error_client_key']; + } else { + $data['error_client_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/worldpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/worldpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_worldpay_service_key'])) { + $data['payment_worldpay_service_key'] = $this->request->post['payment_worldpay_service_key']; + } else { + $data['payment_worldpay_service_key'] = $this->config->get('payment_worldpay_service_key'); + } + + if (isset($this->request->post['payment_worldpay_client_key'])) { + $data['payment_worldpay_client_key'] = $this->request->post['payment_worldpay_client_key']; + } else { + $data['payment_worldpay_client_key'] = $this->config->get('payment_worldpay_client_key'); + } + + if (isset($this->request->post['payment_worldpay_total'])) { + $data['payment_worldpay_total'] = $this->request->post['payment_worldpay_total']; + } else { + $data['payment_worldpay_total'] = $this->config->get('payment_worldpay_total'); + } + + if (isset($this->request->post['payment_worldpay_card'])) { + $data['payment_worldpay_card'] = $this->request->post['payment_worldpay_card']; + } else { + $data['payment_worldpay_card'] = $this->config->get('payment_worldpay_card'); + } + + if (isset($this->request->post['payment_worldpay_order_status_id'])) { + $data['payment_worldpay_order_status_id'] = $this->request->post['payment_worldpay_order_status_id']; + } else { + $data['payment_worldpay_order_status_id'] = $this->config->get('payment_worldpay_order_status_id'); + } + + if (isset($this->request->post['payment_worldpay_geo_zone_id'])) { + $data['payment_worldpay_geo_zone_id'] = $this->request->post['payment_worldpay_geo_zone_id']; + } else { + $data['payment_worldpay_geo_zone_id'] = $this->config->get('payment_worldpay_geo_zone_id'); + } + + if (isset($this->request->post['payment_worldpay_status'])) { + $data['payment_worldpay_status'] = $this->request->post['payment_worldpay_status']; + } else { + $data['payment_worldpay_status'] = $this->config->get('payment_worldpay_status'); + } + + if (isset($this->request->post['payment_worldpay_debug'])) { + $data['payment_worldpay_debug'] = $this->request->post['payment_worldpay_debug']; + } else { + $data['payment_worldpay_debug'] = $this->config->get('payment_worldpay_debug'); + } + + if (isset($this->request->post['payment_worldpay_sort_order'])) { + $data['payment_worldpay_sort_order'] = $this->request->post['payment_worldpay_sort_order']; + } else { + $data['payment_worldpay_sort_order'] = $this->config->get('payment_worldpay_sort_order'); + } + + if (isset($this->request->post['payment_worldpay_secret_token'])) { + $data['payment_worldpay_secret_token'] = $this->request->post['payment_worldpay_secret_token']; + } elseif ($this->config->get('payment_worldpay_secret_token')) { + $data['payment_worldpay_secret_token'] = $this->config->get('payment_worldpay_secret_token'); + } else { + $data['payment_worldpay_secret_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['payment_worldpay_webhook_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/webhook&token=' . $data['payment_worldpay_secret_token']; + + $data['payment_worldpay_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/cron&token=' . $data['payment_worldpay_secret_token']; + + if ($this->config->get('payment_worldpay_last_cron_job_run')) { + $data['payment_worldpay_last_cron_job_run'] = $this->config->get('payment_worldpay_last_cron_job_run'); + } else { + $data['payment_worldpay_last_cron_job_run'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_worldpay_success_status_id'])) { + $data['payment_worldpay_success_status_id'] = $this->request->post['payment_worldpay_success_status_id']; + } else { + $data['payment_worldpay_success_status_id'] = $this->config->get('payment_worldpay_success_status_id'); + } + + if (isset($this->request->post['payment_worldpay_failed_status_id'])) { + $data['payment_worldpay_failed_status_id'] = $this->request->post['payment_worldpay_failed_status_id']; + } else { + $data['payment_worldpay_failed_status_id'] = $this->config->get('payment_worldpay_failed_status_id'); + } + + if (isset($this->request->post['payment_worldpay_settled_status_id'])) { + $data['payment_worldpay_settled_status_id'] = $this->request->post['payment_worldpay_settled_status_id']; + } else { + $data['payment_worldpay_settled_status_id'] = $this->config->get('payment_worldpay_settled_status_id'); + } + + if (isset($this->request->post['payment_worldpay_refunded_status_id'])) { + $data['payment_worldpay_refunded_status_id'] = $this->request->post['payment_worldpay_refunded_status_id']; + } else { + $data['payment_worldpay_refunded_status_id'] = $this->config->get('payment_worldpay_refunded_status_id'); + } + + if (isset($this->request->post['payment_worldpay_partially_refunded_status_id'])) { + $data['payment_worldpay_partially_refunded_status_id'] = $this->request->post['payment_worldpay_partially_refunded_status_id']; + } else { + $data['payment_worldpay_partially_refunded_status_id'] = $this->config->get('payment_worldpay_partially_refunded_status_id'); + } + + if (isset($this->request->post['payment_worldpay_charged_back_status_id'])) { + $data['payment_worldpay_charged_back_status_id'] = $this->request->post['payment_worldpay_charged_back_status_id']; + } else { + $data['payment_worldpay_charged_back_status_id'] = $this->config->get('payment_worldpay_charged_back_status_id'); + } + + if (isset($this->request->post['payment_worldpay_information_requested_status_id'])) { + $data['payment_worldpay_information_requested_status_id'] = $this->request->post['payment_worldpay_information_requested_status_id']; + } else { + $data['payment_worldpay_information_requested_status_id'] = $this->config->get('payment_worldpay_information_requested_status_id'); + } + + if (isset($this->request->post['payment_worldpay_information_supplied_status_id'])) { + $data['payment_worldpay_information_supplied_status_id'] = $this->request->post['payment_worldpay_information_supplied_status_id']; + } else { + $data['payment_worldpay_information_supplied_status_id'] = $this->config->get('payment_worldpay_information_supplied_status_id'); + } + + if (isset($this->request->post['payment_worldpay_chargeback_reversed_status_id'])) { + $data['payment_worldpay_chargeback_reversed_status_id'] = $this->request->post['payment_worldpay_chargeback_reversed_status_id']; + } else { + $data['payment_worldpay_chargeback_reversed_status_id'] = $this->config->get('payment_worldpay_chargeback_reversed_status_id'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/worldpay', $data)); + } + + public function install() { + $this->load->model('extension/payment/worldpay'); + $this->model_extension_payment_worldpay->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/worldpay'); + $this->model_extension_payment_worldpay->uninstall(); + } + + public function order() { + + if ($this->config->get('payment_worldpay_status')) { + + $this->load->model('extension/payment/worldpay'); + + $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->get['order_id']); + + if (!empty($worldpay_order)) { + $this->load->language('extension/payment/worldpay'); + + $worldpay_order['total_released'] = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']); + + $worldpay_order['total_formatted'] = $this->currency->format($worldpay_order['total'], $worldpay_order['currency_code'], false); + $worldpay_order['total_released_formatted'] = $this->currency->format($worldpay_order['total_released'], $worldpay_order['currency_code'], false); + + $data['worldpay_order'] = $worldpay_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/worldpay_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/worldpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/worldpay'); + + $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_worldpay->refund($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_worldpay->logger('Refund result: ' . print_r($refund_response, 1)); + + if ($refund_response['status'] == 'success') { + $this->model_extension_payment_worldpay->addTransaction($worldpay_order['worldpay_order_id'], 'refund', $this->request->post['amount'] * -1); + + $total_refunded = $this->model_extension_payment_worldpay->getTotalRefunded($worldpay_order['worldpay_order_id']); + $total_released = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']); + + $this->model_extension_payment_worldpay->updateRefundStatus($worldpay_order['worldpay_order_id'], 1); + + $json['msg'] = $this->language->get('text_refund_ok_order'); + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $worldpay_order['currency_code'], false); + $json['data']['total_released'] = $this->currency->format($total_released, $worldpay_order['currency_code'], false); + $json['data']['total_refund'] = $this->currency->format($total_refunded, $worldpay_order['currency_code'], false); + $json['data']['refund_status'] = 1; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($refund_response['message']) && !empty($refund_response['message']) ? (string)$refund_response['message'] : 'Unable to refund'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/worldpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_worldpay_service_key']) { + $this->error['error_service_key'] = $this->language->get('error_service_key'); + } + + if (!$this->request->post['payment_worldpay_client_key']) { + $this->error['error_client_key'] = $this->language->get('error_client_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/report/customer_activity.php b/public/admin/controller/extension/report/customer_activity.php new file mode 100644 index 0000000..0d95a51 --- /dev/null +++ b/public/admin/controller/extension/report/customer_activity.php @@ -0,0 +1,179 @@ +<?php +class ControllerExtensionReportCustomerActivity extends Controller { + public function index() { + $this->load->language('extension/report/customer_activity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_activity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_activity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_activity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_activity_status'])) { + $data['report_customer_activity_status'] = $this->request->post['report_customer_activity_status']; + } else { + $data['report_customer_activity_status'] = $this->config->get('report_customer_activity_status'); + } + + if (isset($this->request->post['report_customer_activity_sort_order'])) { + $data['report_customer_activity_sort_order'] = $this->request->post['report_customer_activity_sort_order']; + } else { + $data['report_customer_activity_sort_order'] = $this->config->get('report_customer_activity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_activity_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_activity')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_activity'); + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['activities'] = array(); + + $filter_data = array( + 'filter_customer' => $filter_customer, + 'filter_ip' => $filter_ip, + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'start' => ($page - 1) * 20, + 'limit' => 20 + ); + + $activity_total = $this->model_extension_report_customer->getTotalCustomerActivities($filter_data); + + $results = $this->model_extension_report_customer->getCustomerActivities($filter_data); + + foreach ($results as $result) { + $comment = vsprintf($this->language->get('text_activity_' . $result['key']), json_decode($result['data'], true)); + + $find = array( + 'customer_id=', + 'order_id=' + ); + + $replace = array( + $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=', true), + $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=', true) + ); + + $data['activities'][] = array( + 'comment' => str_replace($find, $replace, $comment), + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + $pagination = new Pagination(); + $pagination->total = $activity_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_activity' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($activity_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($activity_total - $this->config->get('config_limit_admin'))) ? $activity_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $activity_total, ceil($activity_total / $this->config->get('config_limit_admin'))); + + $data['filter_customer'] = $filter_customer; + $data['filter_ip'] = $filter_ip; + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + + return $this->load->view('extension/report/customer_activity_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_order.php b/public/admin/controller/extension/report/customer_order.php new file mode 100644 index 0000000..82f127b --- /dev/null +++ b/public/admin/controller/extension/report/customer_order.php @@ -0,0 +1,176 @@ +<?php +class ControllerExtensionReportCustomerOrder extends Controller { + public function index() { + $this->load->language('extension/report/customer_order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_order_status'])) { + $data['report_customer_order_status'] = $this->request->post['report_customer_order_status']; + } else { + $data['report_customer_order_status'] = $this->config->get('report_customer_order_status'); + } + + if (isset($this->request->post['report_customer_order_sort_order'])) { + $data['report_customer_order_sort_order'] = $this->request->post['report_customer_order_sort_order']; + } else { + $data['report_customer_order_sort_order'] = $this->config->get('report_customer_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_order'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer->getTotalOrders($filter_data); + + $results = $this->model_extension_report_customer->getOrders($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'orders' => $result['orders'], + 'products' => $result['products'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_order' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/customer_order_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_reward.php b/public/admin/controller/extension/report/customer_reward.php new file mode 100644 index 0000000..b7a67c9 --- /dev/null +++ b/public/admin/controller/extension/report/customer_reward.php @@ -0,0 +1,160 @@ +<?php +class ControllerExtensionReportCustomerReward extends Controller { + public function index() { + $this->load->language('extension/report/customer_reward'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_reward', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_reward_status'])) { + $data['report_customer_reward_status'] = $this->request->post['report_customer_reward_status']; + } else { + $data['report_customer_reward_status'] = $this->config->get('report_customer_reward_status'); + } + + if (isset($this->request->post['report_customer_reward_sort_order'])) { + $data['report_customer_reward_sort_order'] = $this->request->post['report_customer_reward_sort_order']; + } else { + $data['report_customer_reward_sort_order'] = $this->config->get('report_customer_reward_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_reward_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_reward')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_reward'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer->getTotalRewardPoints($filter_data); + + $results = $this->model_extension_report_customer->getRewardPoints($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'points' => $result['points'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_reward' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + + return $this->load->view('extension/report/customer_reward_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_search.php b/public/admin/controller/extension/report/customer_search.php new file mode 100644 index 0000000..6a2aa63 --- /dev/null +++ b/public/admin/controller/extension/report/customer_search.php @@ -0,0 +1,201 @@ +<?php +class ControllerExtensionReportCustomerSearch extends Controller { + public function index() { + $this->load->language('extension/report/customer_search'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_search', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_search', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_search', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_search_status'])) { + $data['report_customer_search_status'] = $this->request->post['report_customer_search_status']; + } else { + $data['report_customer_search_status'] = $this->config->get('report_customer_search_status'); + } + + if (isset($this->request->post['report_customer_search_sort_order'])) { + $data['report_customer_search_sort_order'] = $this->request->post['report_customer_search_sort_order']; + } else { + $data['report_customer_search_sort_order'] = $this->config->get('report_customer_search_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_search_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_search')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_search'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_keyword'])) { + $filter_keyword = $this->request->get['filter_keyword']; + } else { + $filter_keyword = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + $this->load->model('catalog/category'); + + $data['searches'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_keyword' => $filter_keyword, + 'filter_customer' => $filter_customer, + 'filter_ip' => $filter_ip, + 'start' => ($page - 1) * 20, + 'limit' => 20 + ); + + $search_total = $this->model_extension_report_customer->getTotalCustomerSearches($filter_data); + + $results = $this->model_extension_report_customer->getCustomerSearches($filter_data); + + foreach ($results as $result) { + $category_info = $this->model_catalog_category->getCategory($result['category_id']); + + if ($category_info) { + $category = ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name']; + } else { + $category = ''; + } + + if ($result['customer_id'] > 0) { + $customer = sprintf($this->language->get('text_customer'), $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true), $result['customer']); + } else { + $customer = $this->language->get('text_guest'); + } + + $data['searches'][] = array( + 'keyword' => $result['keyword'], + 'products' => $result['products'], + 'category' => $category, + 'customer' => $customer, + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode($this->request->get['filter_keyword']); + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $pagination = new Pagination(); + $pagination->total = $search_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_search' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($search_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($search_total - $this->config->get('config_limit_admin'))) ? $search_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $search_total, ceil($search_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_keyword'] = $filter_keyword; + $data['filter_customer'] = $filter_customer; + $data['filter_ip'] = $filter_ip; + + return $this->load->view('extension/report/customer_search_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_transaction.php b/public/admin/controller/extension/report/customer_transaction.php new file mode 100644 index 0000000..1657d34 --- /dev/null +++ b/public/admin/controller/extension/report/customer_transaction.php @@ -0,0 +1,158 @@ +<?php +class ControllerExtensionReportCustomerTransaction extends Controller { + public function index() { + $this->load->language('extension/report/customer_transaction'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_transaction', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_transaction', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_transaction', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_transaction_status'])) { + $data['report_customer_transaction_status'] = $this->request->post['report_customer_transaction_status']; + } else { + $data['report_customer_transaction_status'] = $this->config->get('report_customer_transaction_status'); + } + + if (isset($this->request->post['report_customer_transaction_sort_order'])) { + $data['report_customer_transaction_sort_order'] = $this->request->post['report_customer_transaction_sort_order']; + } else { + $data['report_customer_transaction_sort_order'] = $this->config->get('report_customer_transaction_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_transaction_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_transaction')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_transaction'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer_transaction'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer_transaction->getTotalTransactions($filter_data); + + $results = $this->model_extension_report_customer_transaction->getTransactions($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_transaction' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + + return $this->load->view('extension/report/customer_transaction_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/marketing.php b/public/admin/controller/extension/report/marketing.php new file mode 100644 index 0000000..1d8f465 --- /dev/null +++ b/public/admin/controller/extension/report/marketing.php @@ -0,0 +1,162 @@ +<?php +class ControllerExtensionReportMarketing extends Controller { + public function index() { + $this->load->language('extension/report/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_marketing', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/marketing', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/marketing', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_marketing_status'])) { + $data['report_marketing_status'] = $this->request->post['report_marketing_status']; + } else { + $data['report_marketing_status'] = $this->config->get('report_marketing_status'); + } + + if (isset($this->request->post['report_marketing_sort_order'])) { + $data['report_marketing_sort_order'] = $this->request->post['report_marketing_sort_order']; + } else { + $data['report_marketing_sort_order'] = $this->config->get('report_marketing_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/marketing_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/marketing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/marketing'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/marketing'); + + $data['marketings'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $marketing_total = $this->model_extension_report_marketing->getTotalMarketing($filter_data); + + $results = $this->model_extension_report_marketing->getMarketing($filter_data); + + foreach ($results as $result) { + $data['marketings'][] = array( + 'campaign' => $result['campaign'], + 'code' => $result['code'], + 'clicks' => $result['clicks'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'action' => $this->url->link('marketing/marketing/edit', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $marketing_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=marketing' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($marketing_total - $this->config->get('config_limit_admin'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $marketing_total, ceil($marketing_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/marketing_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/product_purchased.php b/public/admin/controller/extension/report/product_purchased.php new file mode 100644 index 0000000..405da7d --- /dev/null +++ b/public/admin/controller/extension/report/product_purchased.php @@ -0,0 +1,160 @@ +<?php +class ControllerExtensionReportProductPurchased extends Controller { + public function index() { + $this->load->language('extension/report/product_purchased'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_product_purchased', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/product_purchased', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/product_purchased', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_product_purchased_status'])) { + $data['report_product_purchased_status'] = $this->request->post['report_product_purchased_status']; + } else { + $data['report_product_purchased_status'] = $this->config->get('report_product_purchased_status'); + } + + if (isset($this->request->post['report_product_purchased_sort_order'])) { + $data['report_product_purchased_sort_order'] = $this->request->post['report_product_purchased_sort_order']; + } else { + $data['report_product_purchased_sort_order'] = $this->config->get('report_product_purchased_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/product_purchased_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/product_purchased')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/product_purchased'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/product'); + + $data['products'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $product_total = $this->model_extension_report_product->getTotalPurchased($filter_data); + + $results = $this->model_extension_report_product->getPurchased($filter_data); + + foreach ($results as $result) { + $data['products'][] = array( + 'name' => $result['name'], + 'model' => $result['model'], + 'quantity' => $result['quantity'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_purchased' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/product_purchased_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/product_viewed.php b/public/admin/controller/extension/report/product_viewed.php new file mode 100644 index 0000000..4afa4fe --- /dev/null +++ b/public/admin/controller/extension/report/product_viewed.php @@ -0,0 +1,149 @@ +<?php +class ControllerExtensionReportProductViewed extends Controller { + public function index() { + $this->load->language('extension/report/product_viewed'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_product_viewed', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/product_viewed', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/product_viewed', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_product_viewed_status'])) { + $data['report_product_viewed_status'] = $this->request->post['report_product_viewed_status']; + } else { + $data['report_product_viewed_status'] = $this->config->get('report_product_viewed_status'); + } + + if (isset($this->request->post['report_product_viewed_sort_order'])) { + $data['report_product_viewed_sort_order'] = $this->request->post['report_product_viewed_sort_order']; + } else { + $data['report_product_viewed_sort_order'] = $this->config->get('report_product_viewed_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/product_viewed_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/product_viewed')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/product_viewed'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['reset'] = $this->url->link('extension/report/product_viewed/reset', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $this->load->model('extension/report/product'); + + $filter_data = array( + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $data['products'] = array(); + + $product_viewed_total = $this->model_extension_report_product->getTotalProductViews(); + + $product_total = $this->model_extension_report_product->getTotalProductsViewed(); + + $results = $this->model_extension_report_product->getProductsViewed($filter_data); + + foreach ($results as $result) { + if ($result['viewed']) { + $percent = round($result['viewed'] / $product_viewed_total * 100, 2); + } else { + $percent = 0; + } + + $data['products'][] = array( + 'name' => $result['name'], + 'model' => $result['model'], + 'viewed' => $result['viewed'], + 'percent' => $percent . '%' + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_viewed&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + return $this->load->view('extension/report/product_viewed_info', $data); + } + + public function reset() { + $this->load->language('extension/report/product_viewed'); + + if (!$this->user->hasPermission('modify', 'extension/report/product_viewed')) { + $this->session->data['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/report/product'); + + $this->model_extension_report_product->reset(); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->response->redirect($this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_viewed' . $url, true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_coupon.php b/public/admin/controller/extension/report/sale_coupon.php new file mode 100644 index 0000000..aebab08 --- /dev/null +++ b/public/admin/controller/extension/report/sale_coupon.php @@ -0,0 +1,145 @@ +<?php +class ControllerExtensionReportSaleCoupon extends Controller { + public function index() { + $this->load->language('extension/report/sale_coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_coupon', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_coupon', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_coupon', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_coupon_status'])) { + $data['report_sale_coupon_status'] = $this->request->post['report_sale_coupon_status']; + } else { + $data['report_sale_coupon_status'] = $this->config->get('report_sale_coupon_status'); + } + + if (isset($this->request->post['report_sale_coupon_sort_order'])) { + $data['report_sale_coupon_sort_order'] = $this->request->post['report_sale_coupon_sort_order']; + } else { + $data['report_sale_coupon_sort_order'] = $this->config->get('report_sale_coupon_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_coupon_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_coupon'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/coupon'); + + $data['coupons'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $coupon_total = $this->model_extension_report_coupon->getTotalCoupons($filter_data); + + $results = $this->model_extension_report_coupon->getCoupons($filter_data); + + foreach ($results as $result) { + $data['coupons'][] = array( + 'name' => $result['name'], + 'code' => $result['code'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('marketing/coupon/edit', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + $pagination = new Pagination(); + $pagination->total = $coupon_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_coupon' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($coupon_total - $this->config->get('config_limit_admin'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $coupon_total, ceil($coupon_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + + return $this->load->view('extension/report/sale_coupon_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_order.php b/public/admin/controller/extension/report/sale_order.php new file mode 100644 index 0000000..e718ce8 --- /dev/null +++ b/public/admin/controller/extension/report/sale_order.php @@ -0,0 +1,196 @@ +<?php +class ControllerExtensionReportSaleOrder extends Controller { + public function index() { + $this->load->language('extension/report/sale_order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_order_status'])) { + $data['report_sale_order_status'] = $this->request->post['report_sale_order_status']; + } else { + $data['report_sale_order_status'] = $this->config->get('report_sale_order_status'); + } + + if (isset($this->request->post['report_sale_order_sort_order'])) { + $data['report_sale_order_sort_order'] = $this->request->post['report_sale_order_sort_order']; + } else { + $data['report_sale_order_sort_order'] = $this->config->get('report_sale_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_order'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = date('Y-m-d', strtotime(date('Y') . '-' . date('m') . '-01')); + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = date('Y-m-d'); + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalOrders($filter_data); + + $results = $this->model_extension_report_sale->getOrders($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'orders' => $result['orders'], + 'products' => $result['products'], + 'tax' => $this->currency->format($result['tax'], $this->config->get('config_currency')), + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_order' . $url . '&page={page}', true); + + $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_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_order_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_return.php b/public/admin/controller/extension/report/sale_return.php new file mode 100644 index 0000000..85f5767 --- /dev/null +++ b/public/admin/controller/extension/report/sale_return.php @@ -0,0 +1,193 @@ +<?php +class ControllerExtensionReportSaleReturn extends Controller { + public function index() { + $this->load->language('extension/report/sale_return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_return', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_return', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_return', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_return_status'])) { + $data['report_sale_return_status'] = $this->request->post['report_sale_return_status']; + } else { + $data['report_sale_return_status'] = $this->config->get('report_sale_return_status'); + } + + if (isset($this->request->post['report_sale_return_sort_order'])) { + $data['report_sale_return_sort_order'] = $this->request->post['report_sale_return_sort_order']; + } else { + $data['report_sale_return_sort_order'] = $this->config->get('report_sale_return_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_return_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_return'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $filter_return_status_id = $this->request->get['filter_return_status_id']; + } else { + $filter_return_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/return'); + + $data['returns'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_return_status_id' => $filter_return_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_total = $this->model_extension_report_return->getTotalReturns($filter_data); + + $results = $this->model_extension_report_return->getReturns($filter_data); + + foreach ($results as $result) { + $data['returns'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'returns' => $result['returns'] + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $return_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_return' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_total - $this->config->get('config_limit_admin'))) ? $return_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_total, ceil($return_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_return_status_id'] = $filter_return_status_id; + + return $this->load->view('extension/report/sale_return_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_shipping.php b/public/admin/controller/extension/report/sale_shipping.php new file mode 100644 index 0000000..5f56fdc --- /dev/null +++ b/public/admin/controller/extension/report/sale_shipping.php @@ -0,0 +1,195 @@ +<?php +class ControllerExtensionReportSaleShipping extends Controller { + public function index() { + $this->load->language('extension/report/sale_shipping'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_shipping', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_shipping', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_shipping', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_shipping_status'])) { + $data['report_sale_shipping_status'] = $this->request->post['report_sale_shipping_status']; + } else { + $data['report_sale_shipping_status'] = $this->config->get('report_sale_shipping_status'); + } + + if (isset($this->request->post['report_sale_shipping_sort_order'])) { + $data['report_sale_shipping_sort_order'] = $this->request->post['report_sale_shipping_sort_order']; + } else { + $data['report_sale_shipping_sort_order'] = $this->config->get('report_sale_shipping_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_shipping_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_shipping'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalShipping($filter_data); + + $results = $this->model_extension_report_sale->getShipping($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'title' => $result['title'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_shipping' . $url . '&page={page}', true); + + $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_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_shipping_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_tax.php b/public/admin/controller/extension/report/sale_tax.php new file mode 100644 index 0000000..d16cdc6 --- /dev/null +++ b/public/admin/controller/extension/report/sale_tax.php @@ -0,0 +1,197 @@ +<?php +class ControllerExtensionReportSaleTax extends Controller { + public function index() { + $this->load->language('extension/report/sale_tax'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_tax', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_tax', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_tax', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_tax_status'])) { + $data['report_sale_tax_status'] = $this->request->post['report_sale_tax_status']; + } else { + $data['report_sale_tax_status'] = $this->config->get('report_sale_tax_status'); + } + + if (isset($this->request->post['report_sale_tax_sort_order'])) { + $data['report_sale_tax_sort_order'] = $this->request->post['report_sale_tax_sort_order']; + } else { + $data['report_sale_tax_sort_order'] = $this->config->get('report_sale_tax_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_tax_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_tax')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_tax'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + 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 = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalTaxes($filter_data); + + $data['orders'] = array(); + + $results = $this->model_extension_report_sale->getTaxes($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'title' => $result['title'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_tax' . $url . '&page={page}', true); + + $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_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_tax_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/auspost.php b/public/admin/controller/extension/shipping/auspost.php new file mode 100644 index 0000000..8f4f036 --- /dev/null +++ b/public/admin/controller/extension/shipping/auspost.php @@ -0,0 +1,135 @@ +<?php +class ControllerExtensionShippingAusPost extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/auspost'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_auspost', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['api'])) { + $data['error_api'] = $this->error['api']; + } else { + $data['error_api'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_auspost_postcode'])) { + $data['shipping_auspost_postcode'] = $this->request->post['shipping_auspost_postcode']; + } else { + $data['shipping_auspost_postcode'] = $this->config->get('shipping_auspost_postcode'); + } + + if (isset($this->request->post['shipping_auspost_api'])) { + $data['shipping_auspost_api'] = $this->request->post['shipping_auspost_api']; + } else { + $data['shipping_auspost_api'] = $this->config->get('shipping_auspost_api'); + } + + if (isset($this->request->post['shipping_auspost_weight_class_id'])) { + $data['shipping_auspost_weight_class_id'] = $this->request->post['shipping_auspost_weight_class_id']; + } else { + $data['shipping_auspost_weight_class_id'] = $this->config->get('shipping_auspost_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_auspost_tax_class_id'])) { + $data['shipping_auspost_tax_class_id'] = $this->request->post['shipping_auspost_tax_class_id']; + } else { + $data['shipping_auspost_tax_class_id'] = $this->config->get('shipping_auspost_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_auspost_geo_zone_id'])) { + $data['shipping_auspost_geo_zone_id'] = $this->request->post['shipping_auspost_geo_zone_id']; + } else { + $data['shipping_auspost_geo_zone_id'] = $this->config->get('shipping_auspost_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_auspost_status'])) { + $data['shipping_auspost_status'] = $this->request->post['shipping_auspost_status']; + } else { + $data['shipping_auspost_status'] = $this->config->get('shipping_auspost_status'); + } + + if (isset($this->request->post['shipping_auspost_sort_order'])) { + $data['shipping_auspost_sort_order'] = $this->request->post['shipping_auspost_sort_order']; + } else { + $data['shipping_auspost_sort_order'] = $this->config->get('shipping_auspost_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/auspost', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/auspost')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['shipping_auspost_api'])) { + $this->error['api'] = $this->language->get('error_api'); + } + + if (!preg_match('/^[0-9]{4}$/', $this->request->post['shipping_auspost_postcode'])) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/ec_ship.php b/public/admin/controller/extension/shipping/ec_ship.php new file mode 100644 index 0000000..b743c6c --- /dev/null +++ b/public/admin/controller/extension/shipping/ec_ship.php @@ -0,0 +1,229 @@ +<?php +class ControllerExtensionShippingECShip extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/ec_ship'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_ec_ship', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['api_username'])) { + $data['error_api_username'] = $this->error['entry_api_username']; + } else { + $data['error_api_username'] = ''; + } + + if (isset($this->error['api_key'])) { + $data['error_api_key'] = $this->error['api_key']; + } else { + $data['error_api_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/ec_ship', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/ec_ship', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_ec_ship_api_key'])) { + $data['shipping_ec_ship_api_key'] = $this->request->post['shipping_ec_ship_api_key']; + } else { + $data['shipping_ec_ship_api_key'] = $this->config->get('shipping_ec_ship_api_key'); + } + + if (isset($this->request->post['shipping_ec_ship_username'])) { + $data['shipping_ec_ship_username'] = $this->request->post['shipping_ec_ship_username']; + } else { + $data['shipping_ec_ship_username'] = $this->config->get('shipping_ec_ship_username'); + } + + if (isset($this->request->post['shipping_ec_ship_api_username'])) { + $data['shipping_ec_ship_api_username'] = $this->request->post['shipping_ec_ship_api_username']; + } else { + $data['shipping_ec_ship_api_username'] = $this->config->get('shipping_ec_ship_api_username'); + } + + if (isset($this->request->post['shipping_ec_ship_test'])) { + $data['shipping_ec_ship_test'] = $this->request->post['shipping_ec_ship_test']; + } else { + $data['shipping_ec_ship_test'] = $this->config->get('shipping_ec_ship_test'); + } + + if (isset($this->request->post['shipping_ec_ship_air_registered_mail'])) { + $data['shipping_ec_ship_air_registered_mail'] = $this->request->post['shipping_ec_ship_air_registered_mail']; + } else { + $data['shipping_ec_ship_air_registered_mail'] = $this->config->get('shipping_ec_ship_air_registered_mail'); + } + + if (isset($this->request->post['shipping_ec_ship_air_parcel'])) { + $data['shipping_ec_ship_air_parcel'] = $this->request->post['shipping_ec_ship_air_parcel']; + } else { + $data['shipping_ec_ship_air_parcel'] = $this->config->get('shipping_ec_ship_air_parcel'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_us'])) { + $data['shipping_ec_ship_e_express_service_to_us'] = $this->request->post['shipping_ec_ship_e_express_service_to_us']; + } else { + $data['shipping_ec_ship_e_express_service_to_us'] = $this->config->get('shipping_ec_ship_e_express_service_to_us'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_canada'])) { + $data['shipping_ec_ship_e_express_service_to_canada'] = $this->request->post['shipping_ec_ship_e_express_service_to_canada']; + } else { + $data['shipping_ec_ship_e_express_service_to_canada'] = $this->config->get('shipping_ec_ship_e_express_service_to_canada'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_united_kingdom'])) { + $data['shipping_ec_ship_e_express_service_to_united_kingdom'] = $this->request->post['shipping_ec_ship_e_express_service_to_united_kingdom']; + } else { + $data['shipping_ec_ship_e_express_service_to_united_kingdom'] = $this->config->get('shipping_ec_ship_e_express_service_to_united_kingdom'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_russia'])) { + $data['shipping_ec_ship_e_express_service_to_russia'] = $this->request->post['shipping_ec_ship_e_express_service_to_russia']; + } else { + $data['shipping_ec_ship_e_express_service_to_russia'] = $this->config->get('shipping_ec_ship_e_express_service_to_russia'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_one'])) { + $data['shipping_ec_ship_e_express_service_one'] = $this->request->post['shipping_ec_ship_e_express_service_one']; + } else { + $data['shipping_ec_ship_e_express_service_one'] = $this->config->get('shipping_ec_ship_e_express_service_one'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_two'])) { + $data['shipping_ec_ship_e_express_service_two'] = $this->request->post['shipping_ec_ship_e_express_service_two']; + } else { + $data['shipping_ec_ship_e_express_service_two'] = $this->config->get('shipping_ec_ship_e_express_service_two'); + } + + if (isset($this->request->post['shipping_ec_ship_speed_post'])) { + $data['shipping_ec_ship_speed_post'] = $this->request->post['shipping_ec_ship_speed_post']; + } else { + $data['shipping_ec_ship_speed_post'] = $this->config->get('shipping_ec_ship_speed_post'); + } + + if (isset($this->request->post['shipping_ec_ship_smart_post'])) { + $data['shipping_ec_ship_smart_post'] = $this->request->post['shipping_ec_ship_smart_post']; + } else { + $data['shipping_ec_ship_smart_post'] = $this->config->get('shipping_ec_ship_smart_post'); + } + + if (isset($this->request->post['shipping_ec_ship_local_courier_post'])) { + $data['shipping_ec_ship_local_courier_post'] = $this->request->post['shipping_ec_ship_local_courier_post']; + } else { + $data['shipping_ec_ship_local_courier_post'] = $this->config->get('shipping_ec_ship_local_courier_post'); + } + + if (isset($this->request->post['shipping_ec_ship_local_parcel'])) { + $data['shipping_ec_ship_local_parcel'] = $this->request->post['shipping_ec_ship_local_parcel']; + } else { + $data['shipping_ec_ship_local_parcel'] = $this->config->get('shipping_ec_ship_local_parcel'); + } + + if (isset($this->request->post['shipping_ec_ship_weight_class_id'])) { + $data['shipping_ec_ship_weight_class_id'] = $this->request->post['shipping_ec_ship_weight_class_id']; + } else { + $data['shipping_ec_ship_weight_class_id'] = $this->config->get('shipping_ec_ship_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_ec_ship_tax_class_id'])) { + $data['shipping_ec_ship_tax_class_id'] = $this->request->post['shipping_ec_ship_tax_class_id']; + } else { + $data['shipping_ec_ship_tax_class_id'] = $this->config->get('shipping_ec_ship_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_ec_ship_geo_zone_id'])) { + $data['shipping_ec_ship_geo_zone_id'] = $this->request->post['shipping_ec_ship_geo_zone_id']; + } else { + $data['shipping_ec_ship_geo_zone_id'] = $this->config->get('shipping_ec_ship_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_ec_ship_status'])) { + $data['shipping_ec_ship_status'] = $this->request->post['shipping_ec_ship_status']; + } else { + $data['shipping_ec_ship_status'] = $this->config->get('shipping_ec_ship_status'); + } + + if (isset($this->request->post['shipping_ec_ship_sort_order'])) { + $data['shipping_ec_ship_sort_order'] = $this->request->post['shipping_ec_ship_sort_order']; + } else { + $data['shipping_ec_ship_sort_order'] = $this->config->get('shipping_ec_ship_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/ec_ship', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/ec_ship')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_ec_ship_api_key']) { + $this->error['api_key'] = $this->language->get('error_api_key'); + } + + if (!$this->request->post['shipping_ec_ship_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['shipping_ec_ship_api_username']) { + $this->error['api_username'] = $this->language->get('error_api_username'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/fedex.php b/public/admin/controller/extension/shipping/fedex.php new file mode 100644 index 0000000..37a3f8e --- /dev/null +++ b/public/admin/controller/extension/shipping/fedex.php @@ -0,0 +1,378 @@ +<?php +class ControllerExtensionShippingFedex extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/fedex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_fedex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = ''; + } + + if (isset($this->error['meter'])) { + $data['error_meter'] = $this->error['meter']; + } else { + $data['error_meter'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_fedex_key'])) { + $data['shipping_fedex_key'] = $this->request->post['shipping_fedex_key']; + } else { + $data['shipping_fedex_key'] = $this->config->get('shipping_fedex_key'); + } + + if (isset($this->request->post['shipping_fedex_password'])) { + $data['shipping_fedex_password'] = $this->request->post['shipping_fedex_password']; + } else { + $data['shipping_fedex_password'] = $this->config->get('shipping_fedex_password'); + } + + if (isset($this->request->post['shipping_fedex_account'])) { + $data['shipping_fedex_account'] = $this->request->post['shipping_fedex_account']; + } else { + $data['shipping_fedex_account'] = $this->config->get('shipping_fedex_account'); + } + + if (isset($this->request->post['shipping_fedex_meter'])) { + $data['shipping_fedex_meter'] = $this->request->post['shipping_fedex_meter']; + } else { + $data['shipping_fedex_meter'] = $this->config->get('shipping_fedex_meter'); + } + + if (isset($this->request->post['shipping_fedex_postcode'])) { + $data['shipping_fedex_postcode'] = $this->request->post['shipping_fedex_postcode']; + } else { + $data['shipping_fedex_postcode'] = $this->config->get('shipping_fedex_postcode'); + } + + if (isset($this->request->post['shipping_fedex_test'])) { + $data['shipping_fedex_test'] = $this->request->post['shipping_fedex_test']; + } else { + $data['shipping_fedex_test'] = $this->config->get('shipping_fedex_test'); + } + + if (isset($this->request->post['shipping_fedex_service'])) { + $data['shipping_fedex_service'] = $this->request->post['shipping_fedex_service']; + } elseif ($this->config->has('shipping_fedex_service')) { + $data['shipping_fedex_service'] = $this->config->get('shipping_fedex_service'); + } else { + $data['shipping_fedex_service'] = array(); + } + + $data['services'] = array(); + + $data['services'][] = array( + 'text' => $this->language->get('text_europe_first_international_priority'), + 'value' => 'EUROPE_FIRST_INTERNATIONAL_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_1_day_freight'), + 'value' => 'FEDEX_1_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day'), + 'value' => 'FEDEX_2_DAY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day_am'), + 'value' => 'FEDEX_2_DAY_AM' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day_freight'), + 'value' => 'FEDEX_2_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_3_day_freight'), + 'value' => 'FEDEX_3_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_express_saver'), + 'value' => 'FEDEX_EXPRESS_SAVER' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_first_freight'), + 'value' => 'FEDEX_FIRST_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_freight_economy'), + 'value' => 'FEDEX_FREIGHT_ECONOMY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_freight_priority'), + 'value' => 'FEDEX_FREIGHT_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_ground'), + 'value' => 'FEDEX_GROUND' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_first_overnight'), + 'value' => 'FIRST_OVERNIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_ground_home_delivery'), + 'value' => 'GROUND_HOME_DELIVERY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_economy'), + 'value' => 'INTERNATIONAL_ECONOMY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_economy_freight'), + 'value' => 'INTERNATIONAL_ECONOMY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_first'), + 'value' => 'INTERNATIONAL_FIRST' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_priority'), + 'value' => 'INTERNATIONAL_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_priority_freight'), + 'value' => 'INTERNATIONAL_PRIORITY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_priority_overnight'), + 'value' => 'PRIORITY_OVERNIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_smart_post'), + 'value' => 'SMART_POST' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_standard_overnight'), + 'value' => 'STANDARD_OVERNIGHT' + ); + + if (isset($this->request->post['shipping_fedex_length'])) { + $data['shipping_fedex_length'] = $this->request->post['shipping_fedex_length']; + } else { + $data['shipping_fedex_length'] = $this->config->get('shipping_fedex_length'); + } + + if (isset($this->request->post['shipping_fedex_width'])) { + $data['shipping_fedex_width'] = $this->request->post['shipping_fedex_width']; + } else { + $data['shipping_fedex_width'] = $this->config->get('shipping_fedex_width'); + } + + if (isset($this->request->post['shipping_fedex_height'])) { + $data['shipping_fedex_height'] = $this->request->post['shipping_fedex_height']; + } else { + $data['shipping_fedex_height'] = $this->config->get('shipping_fedex_height'); + } + + if (isset($this->request->post['shipping_fedex_length_class_id'])) { + $data['shipping_fedex_length_class_id'] = $this->request->post['shipping_fedex_length_class_id']; + } else { + $data['shipping_fedex_length_class_id'] = $this->config->get('shipping_fedex_length_class_id'); + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['shipping_fedex_dropoff_type'])) { + $data['shipping_fedex_dropoff_type'] = $this->request->post['shipping_fedex_dropoff_type']; + } else { + $data['shipping_fedex_dropoff_type'] = $this->config->get('shipping_fedex_dropoff_type'); + } + + if (isset($this->request->post['shipping_fedex_packaging_type'])) { + $data['shipping_fedex_packaging_type'] = $this->request->post['shipping_fedex_packaging_type']; + } else { + $data['shipping_fedex_packaging_type'] = $this->config->get('shipping_fedex_packaging_type'); + } + + if (isset($this->request->post['shipping_fedex_rate_type'])) { + $data['shipping_fedex_rate_type'] = $this->request->post['shipping_fedex_rate_type']; + } else { + $data['shipping_fedex_rate_type'] = $this->config->get('shipping_fedex_rate_type'); + } + + if (isset($this->request->post['shipping_fedex_destination_type'])) { + $data['shipping_fedex_destination_type'] = $this->request->post['shipping_fedex_destination_type']; + } else { + $data['shipping_fedex_destination_type'] = $this->config->get('shipping_fedex_destination_type'); + } + + if (isset($this->request->post['shipping_fedex_display_time'])) { + $data['shipping_fedex_display_time'] = $this->request->post['shipping_fedex_display_time']; + } else { + $data['shipping_fedex_display_time'] = $this->config->get('shipping_fedex_display_time'); + } + + if (isset($this->request->post['shipping_fedex_display_weight'])) { + $data['shipping_fedex_display_weight'] = $this->request->post['shipping_fedex_display_weight']; + } else { + $data['shipping_fedex_display_weight'] = $this->config->get('shipping_fedex_display_weight'); + } + + if (isset($this->request->post['shipping_fedex_weight_class_id'])) { + $data['shipping_fedex_weight_class_id'] = $this->request->post['shipping_fedex_weight_class_id']; + } else { + $data['shipping_fedex_weight_class_id'] = $this->config->get('shipping_fedex_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_fedex_tax_class_id'])) { + $data['shipping_fedex_tax_class_id'] = $this->request->post['shipping_fedex_tax_class_id']; + } else { + $data['shipping_fedex_tax_class_id'] = $this->config->get('shipping_fedex_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_fedex_geo_zone_id'])) { + $data['shipping_fedex_geo_zone_id'] = $this->request->post['shipping_fedex_geo_zone_id']; + } else { + $data['shipping_fedex_geo_zone_id'] = $this->config->get('shipping_fedex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_fedex_status'])) { + $data['shipping_fedex_status'] = $this->request->post['shipping_fedex_status']; + } else { + $data['shipping_fedex_status'] = $this->config->get('shipping_fedex_status'); + } + + if (isset($this->request->post['shipping_fedex_sort_order'])) { + $data['shipping_fedex_sort_order'] = $this->request->post['shipping_fedex_sort_order']; + } else { + $data['shipping_fedex_sort_order'] = $this->config->get('shipping_fedex_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/fedex', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/fedex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_fedex_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['shipping_fedex_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['shipping_fedex_account']) { + $this->error['account'] = $this->language->get('error_account'); + } + + if (!$this->request->post['shipping_fedex_meter']) { + $this->error['meter'] = $this->language->get('error_meter'); + } + + if (!$this->request->post['shipping_fedex_postcode']) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + if (!$this->request->post['shipping_fedex_length'] || !$this->request->post['shipping_fedex_width'] || !$this->request->post['shipping_fedex_height']) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/flat.php b/public/admin/controller/extension/shipping/flat.php new file mode 100644 index 0000000..1d4e161 --- /dev/null +++ b/public/admin/controller/extension/shipping/flat.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionShippingFlat extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/flat'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_flat', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/flat', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/flat', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_flat_cost'])) { + $data['shipping_flat_cost'] = $this->request->post['shipping_flat_cost']; + } else { + $data['shipping_flat_cost'] = $this->config->get('shipping_flat_cost'); + } + + if (isset($this->request->post['shipping_flat_tax_class_id'])) { + $data['shipping_flat_tax_class_id'] = $this->request->post['shipping_flat_tax_class_id']; + } else { + $data['shipping_flat_tax_class_id'] = $this->config->get('shipping_flat_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_flat_geo_zone_id'])) { + $data['shipping_flat_geo_zone_id'] = $this->request->post['shipping_flat_geo_zone_id']; + } else { + $data['shipping_flat_geo_zone_id'] = $this->config->get('shipping_flat_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_flat_status'])) { + $data['shipping_flat_status'] = $this->request->post['shipping_flat_status']; + } else { + $data['shipping_flat_status'] = $this->config->get('shipping_flat_status'); + } + + if (isset($this->request->post['shipping_flat_sort_order'])) { + $data['shipping_flat_sort_order'] = $this->request->post['shipping_flat_sort_order']; + } else { + $data['shipping_flat_sort_order'] = $this->config->get('shipping_flat_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/flat', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/flat')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/free.php b/public/admin/controller/extension/shipping/free.php new file mode 100644 index 0000000..c7828a6 --- /dev/null +++ b/public/admin/controller/extension/shipping/free.php @@ -0,0 +1,89 @@ +<?php +class ControllerExtensionShippingFree extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/free'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_free', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/free', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/free', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_free_total'])) { + $data['shipping_free_total'] = $this->request->post['shipping_free_total']; + } else { + $data['shipping_free_total'] = $this->config->get('shipping_free_total'); + } + + if (isset($this->request->post['shipping_free_geo_zone_id'])) { + $data['shipping_free_geo_zone_id'] = $this->request->post['shipping_free_geo_zone_id']; + } else { + $data['shipping_free_geo_zone_id'] = $this->config->get('shipping_free_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_free_status'])) { + $data['shipping_free_status'] = $this->request->post['shipping_free_status']; + } else { + $data['shipping_free_status'] = $this->config->get('shipping_free_status'); + } + + if (isset($this->request->post['shipping_free_sort_order'])) { + $data['shipping_free_sort_order'] = $this->request->post['shipping_free_sort_order']; + } else { + $data['shipping_free_sort_order'] = $this->config->get('shipping_free_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/free', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/free')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/item.php b/public/admin/controller/extension/shipping/item.php new file mode 100644 index 0000000..0e4bfc7 --- /dev/null +++ b/public/admin/controller/extension/shipping/item.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionShippingItem extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/item'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_item', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/item', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/item', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_item_cost'])) { + $data['shipping_item_cost'] = $this->request->post['shipping_item_cost']; + } else { + $data['shipping_item_cost'] = $this->config->get('shipping_item_cost'); + } + + if (isset($this->request->post['shipping_item_tax_class_id'])) { + $data['shipping_item_tax_class_id'] = $this->request->post['shipping_item_tax_class_id']; + } else { + $data['shipping_item_tax_class_id'] = $this->config->get('shipping_item_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_item_geo_zone_id'])) { + $data['shipping_item_geo_zone_id'] = $this->request->post['shipping_item_geo_zone_id']; + } else { + $data['shipping_item_geo_zone_id'] = $this->config->get('shipping_item_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_item_status'])) { + $data['shipping_item_status'] = $this->request->post['shipping_item_status']; + } else { + $data['shipping_item_status'] = $this->config->get('shipping_item_status'); + } + + if (isset($this->request->post['shipping_item_sort_order'])) { + $data['shipping_item_sort_order'] = $this->request->post['shipping_item_sort_order']; + } else { + $data['shipping_item_sort_order'] = $this->config->get('shipping_item_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/item', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/item')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/parcelforce_48.php b/public/admin/controller/extension/shipping/parcelforce_48.php new file mode 100644 index 0000000..6e6d49e --- /dev/null +++ b/public/admin/controller/extension/shipping/parcelforce_48.php @@ -0,0 +1,127 @@ +<?php +class ControllerExtensionShippingParcelforce48 extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/parcelforce_48'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_parcelforce_48', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/parcelforce_48', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/parcelforce_48', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_parcelforce_48_rate'])) { + $data['shipping_parcelforce_48_rate'] = $this->request->post['shipping_parcelforce_48_rate']; + } elseif ($this->config->get('shipping_parcelforce_48_rate')) { + $data['shipping_parcelforce_48_rate'] = $this->config->get('shipping_parcelforce_48_rate'); + } else { + $data['shipping_parcelforce_48_rate'] = '10:15.99,12:19.99,14:20.99,16:21.99,18:21.99,20:21.99,22:26.99,24:30.99,26:34.99,28:38.99,30:42.99,35:52.99,40:62.99,45:72.99,50:82.99,55:92.99,60:102.99,65:112.99,70:122.99,75:132.99,80:142.99,85:152.99,90:162.99,95:172.99,100:182.99'; + } + + if (isset($this->request->post['shipping_parcelforce_48_insurance'])) { + $data['shipping_parcelforce_48_insurance'] = $this->request->post['shipping_parcelforce_48_insurance']; + } elseif ($this->config->get('shipping_parcelforce_48_insurance')) { + $data['shipping_parcelforce_48_insurance'] = $this->config->get('shipping_parcelforce_48_insurance'); + } else { + $data['shipping_parcelforce_48_insurance'] = '150:0,500:12,1000:24,1500:36,2000:48,2500:60'; + } + + if (isset($this->request->post['shipping_parcelforce_48_display_weight'])) { + $data['shipping_parcelforce_48_display_weight'] = $this->request->post['shipping_parcelforce_48_display_weight']; + } else { + $data['shipping_parcelforce_48_display_weight'] = $this->config->get('shipping_parcelforce_48_display_weight'); + } + + if (isset($this->request->post['shipping_parcelforce_48_display_insurance'])) { + $data['shipping_parcelforce_48_display_insurance'] = $this->request->post['shipping_parcelforce_48_display_insurance']; + } else { + $data['shipping_parcelforce_48_display_insurance'] = $this->config->get('shipping_parcelforce_48_display_insurance'); + } + + if (isset($this->request->post['shipping_parcelforce_48_display_time'])) { + $data['shipping_parcelforce_48_display_time'] = $this->request->post['shipping_parcelforce_48_display_time']; + } else { + $data['shipping_parcelforce_48_display_time'] = $this->config->get('shipping_parcelforce_48_display_time'); + } + + if (isset($this->request->post['shipping_parcelforce_48_tax_class_id'])) { + $data['shipping_parcelforce_48_tax_class_id'] = $this->request->post['shipping_parcelforce_48_tax_class_id']; + } else { + $data['shipping_parcelforce_48_tax_class_id'] = $this->config->get('shipping_parcelforce_48_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_parcelforce_48_geo_zone_id'])) { + $data['shipping_parcelforce_48_geo_zone_id'] = $this->request->post['shipping_parcelforce_48_geo_zone_id']; + } else { + $data['shipping_parcelforce_48_geo_zone_id'] = $this->config->get('shipping_parcelforce_48_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_parcelforce_48_status'])) { + $data['shipping_parcelforce_48_status'] = $this->request->post['shipping_parcelforce_48_status']; + } else { + $data['shipping_parcelforce_48_status'] = $this->config->get('shipping_parcelforce_48_status'); + } + + if (isset($this->request->post['shipping_parcelforce_48_sort_order'])) { + $data['shipping_parcelforce_48_sort_order'] = $this->request->post['shipping_parcelforce_48_sort_order']; + } else { + $data['shipping_parcelforce_48_sort_order'] = $this->config->get('shipping_parcelforce_48_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/parcelforce_48', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/parcelforce_48')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/pickup.php b/public/admin/controller/extension/shipping/pickup.php new file mode 100644 index 0000000..7347148 --- /dev/null +++ b/public/admin/controller/extension/shipping/pickup.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionShippingPickup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/pickup'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_pickup', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/pickup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/pickup', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_pickup_geo_zone_id'])) { + $data['shipping_pickup_geo_zone_id'] = $this->request->post['shipping_pickup_geo_zone_id']; + } else { + $data['shipping_pickup_geo_zone_id'] = $this->config->get('shipping_pickup_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_pickup_status'])) { + $data['shipping_pickup_status'] = $this->request->post['shipping_pickup_status']; + } else { + $data['shipping_pickup_status'] = $this->config->get('shipping_pickup_status'); + } + + if (isset($this->request->post['shipping_pickup_sort_order'])) { + $data['shipping_pickup_sort_order'] = $this->request->post['shipping_pickup_sort_order']; + } else { + $data['shipping_pickup_sort_order'] = $this->config->get('shipping_pickup_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/pickup', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/pickup')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/royal_mail.php b/public/admin/controller/extension/shipping/royal_mail.php new file mode 100644 index 0000000..34f446b --- /dev/null +++ b/public/admin/controller/extension/shipping/royal_mail.php @@ -0,0 +1,403 @@ +<?php +class ControllerExtensionShippingRoyalMail extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/royal_mail'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_royal_mail', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/royal_mail', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/royal_mail', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + // Special Delivery < 500 + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_rate'])) { + $data['shipping_royal_mail_special_delivery_500_rate'] = $this->request->post['shipping_royal_mail_special_delivery_500_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_500_rate')) { + $data['shipping_royal_mail_special_delivery_500_rate'] = $this->config->get('shipping_royal_mail_special_delivery_500_rate'); + } else { + $data['shipping_royal_mail_special_delivery_500_rate'] = '0.1:6.40,0.5:7.15,1:8.45,2:11.00,10:26.60,20:41.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_insurance'])) { + $data['shipping_royal_mail_special_delivery_500_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_500_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_500_insurance')) { + $data['shipping_royal_mail_special_delivery_500_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_500_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_500_insurance'] = '0:500'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_status'])) { + $data['shipping_royal_mail_special_delivery_500_status'] = $this->request->post['shipping_royal_mail_special_delivery_500_status']; + } else { + $data['shipping_royal_mail_special_delivery_500_status'] = $this->config->get('shipping_royal_mail_special_delivery_500_status'); + } + + // Special Delivery < 1000 + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_rate'])) { + $data['shipping_royal_mail_special_delivery_1000_rate'] = $this->request->post['shipping_royal_mail_special_delivery_1000_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_1000_rate')) { + $data['shipping_royal_mail_special_delivery_1000_rate'] = $this->config->get('shipping_royal_mail_special_delivery_1000_rate'); + } else { + $data['shipping_royal_mail_special_delivery_1000_rate'] = '0.1:7.40,0.5:8.15,1:9.45,2:12.00,10:27.60,20:42.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_insurance'])) { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_1000_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_1000_insurance')) { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_1000_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = '0:1000'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_status'])) { + $data['shipping_royal_mail_special_delivery_1000_status'] = $this->request->post['shipping_royal_mail_special_delivery_1000_status']; + } else { + $data['shipping_royal_mail_special_delivery_1000_status'] = $this->config->get('shipping_royal_mail_special_delivery_1000_status'); + } + + // Special Delivery < 2500 + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_rate'])) { + $data['shipping_royal_mail_special_delivery_2500_rate'] = $this->request->post['shipping_royal_mail_special_delivery_2500_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_2500_rate')) { + $data['shipping_royal_mail_special_delivery_2500_rate'] = $this->config->get('shipping_royal_mail_special_delivery_2500_rate'); + } else { + $data['shipping_royal_mail_special_delivery_2500_rate'] = '0.1:9.40,0.5:10.15,1:11.45,2:14.00,10:29.60,20:44.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_insurance'])) { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_2500_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_2500_insurance')) { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_2500_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = '0:2500'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_status'])) { + $data['shipping_royal_mail_special_delivery_2500_status'] = $this->request->post['shipping_royal_mail_special_delivery_2500_status']; + } else { + $data['shipping_royal_mail_special_delivery_2500_status'] = $this->config->get('shipping_royal_mail_special_delivery_2500_status'); + } + + // 1st Class Signed + if (isset($this->request->post['shipping_royal_mail_1st_class_signed_rate'])) { + $data['shipping_royal_mail_1st_class_signed_rate'] = $this->request->post['shipping_royal_mail_1st_class_signed_rate']; + } elseif ($this->config->has('shipping_royal_mail_1st_class_signed_rate')) { + $data['shipping_royal_mail_1st_class_signed_rate'] = $this->config->get('shipping_royal_mail_1st_class_signed_rate'); + } else { + $data['shipping_royal_mail_1st_class_signed_rate'] = '0.1:2.03,0.25:2.34,0.5:2.75,0.75:3.48,1:6.75,2:10.00,5:16.95,10:23.00,20:34.50'; + } + + if (isset($this->request->post['shipping_royal_mail_1st_class_signed_status'])) { + $data['shipping_royal_mail_1st_class_signed_status'] = $this->request->post['shipping_royal_mail_1st_class_signed_status']; + } else { + $data['shipping_royal_mail_1st_class_signed_status'] = $this->config->get('shipping_royal_mail_1st_class_signed_status'); + } + + // 2nd Class Signed + if (isset($this->request->post['shipping_royal_mail_2nd_class_signed_rate'])) { + $data['shipping_royal_mail_2nd_class_signed_rate'] = $this->request->post['shipping_royal_mail_2nd_class_signed_rate']; + } elseif ($this->config->has('shipping_royal_mail_2nd_class_signed_rate')) { + $data['shipping_royal_mail_2nd_class_signed_rate'] = $this->config->get('shipping_royal_mail_2nd_class_signed_rate'); + } else { + $data['shipping_royal_mail_2nd_class_signed_rate'] = '0.1:1.83,0.25:2.27,0.5:2.58,0.75:3.11,1:6.30,2:9.10,5:14.85,10:21.35,20:29.65'; + } + + if (isset($this->request->post['shipping_royal_mail_2nd_class_signed_status'])) { + $data['shipping_royal_mail_2nd_class_signed_status'] = $this->request->post['shipping_royal_mail_2nd_class_signed_status']; + } else { + $data['shipping_royal_mail_2nd_class_signed_status'] = $this->config->get('shipping_royal_mail_2nd_class_signed_status'); + } + + // 1st Class Standard + if (isset($this->request->post['shipping_royal_mail_1st_class_standard_rate'])) { + $data['shipping_royal_mail_1st_class_standard_rate'] = $this->request->post['shipping_royal_mail_1st_class_standard_rate']; + } elseif ($this->config->has('shipping_royal_mail_1st_class_standard_rate')) { + $data['shipping_royal_mail_1st_class_standard_rate'] = $this->config->get('shipping_royal_mail_1st_class_standard_rate'); + } else { + $data['shipping_royal_mail_1st_class_standard_rate'] = '0.1:0.93,0.25:1.24,0.5:1.65,0.75:2.38,1:5.65,2:8.90,5:15.85,10:21.90,20:33.40'; + } + + if (isset($this->request->post['shipping_royal_mail_1st_class_standard_status'])) { + $data['shipping_royal_mail_1st_class_standard_status'] = $this->request->post['shipping_royal_mail_1st_class_standard_status']; + } else { + $data['shipping_royal_mail_1st_class_standard_status'] = $this->config->get('shipping_royal_mail_1st_class_standard_status'); + } + + // 2nd Class Standard + if (isset($this->request->post['shipping_royal_mail_2nd_class_standard_rate'])) { + $data['shipping_royal_mail_2nd_class_standard_rate'] = $this->request->post['shipping_royal_mail_2nd_class_standard_rate']; + } elseif ($this->config->has('shipping_royal_mail_2nd_class_standard_rate')) { + $data['shipping_royal_mail_2nd_class_standard_rate'] = $this->config->get('shipping_royal_mail_2nd_class_standard_rate'); + } else { + $data['shipping_royal_mail_2nd_class_standard_rate'] = '0.1:0.73,.25:1.17,.5:1.48,.75:2.01,1:5.20,2:8.00,5:13.75,10:20.25,20:28.55'; + } + + if (isset($this->request->post['shipping_royal_mail_2nd_class_standard_status'])) { + $data['shipping_royal_mail_2nd_class_standard_status'] = $this->request->post['shipping_royal_mail_2nd_class_standard_status']; + } else { + $data['shipping_royal_mail_2nd_class_standard_status'] = $this->config->get('shipping_royal_mail_2nd_class_standard_status'); + } + + // International Standard + if (isset($this->request->post['shipping_royal_mail_international_standard_eu_rate'])) { + $data['shipping_royal_mail_international_standard_eu_rate'] = $this->request->post['shipping_royal_mail_international_standard_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_eu_rate')) { + $data['shipping_royal_mail_international_standard_eu_rate'] = $this->config->get('shipping_royal_mail_international_standard_eu_rate'); + } else { + $data['shipping_royal_mail_international_standard_eu_rate'] = '0.01:0.97,0.02:0.97,0.06:1.47,0.1:3.20,0.25:3.70,0.5:5.15,0.75:6.60,1.25:9.50,1.5:10.95,1.75:12.40,2:13.85'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_zone_1_rate'])) { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_standard_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_zone_1_rate')) { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_standard_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = '0.01:0.97,0.02:1.28,0.06:2.15,0.1:3.80,0.25:4.75,0.5:7.45,0.75:10.15,1:12.85,1.25:15.55,1.5:18.25,1.75:20.95,2:23.65'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_zone_2_rate'])) { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_standard_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_zone_2_rate')) { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_standard_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = '0.01:0.97,0.02:1.28,0.06:2.15,0.1:4.00,0.25:5.05,0.5:7.90,0.75:10.75,1:13.60,1.25:16.45,1.5:19.30,1.75:22.15,2:25.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_status'])) { + $data['shipping_royal_mail_international_standard_status'] = $this->request->post['shipping_royal_mail_international_standard_status']; + } else { + $data['shipping_royal_mail_international_standard_status'] = $this->config->get('shipping_royal_mail_international_standard_status'); + } + + // International Tracked & Signed + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_eu_rate')) { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.50:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_zone_1_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_zone_1_rate')) { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = '0.02:6.28,0.06:7.15,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_zone_2_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_zone_2_rate')) { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_status'])) { + $data['shipping_royal_mail_international_tracked_signed_status'] = $this->request->post['shipping_royal_mail_international_tracked_signed_status']; + } else { + $data['shipping_royal_mail_international_tracked_signed_status'] = $this->config->get('shipping_royal_mail_international_tracked_signed_status'); + } + + // International Tracked + // Europe + if (isset($this->request->post['shipping_royal_mail_international_tracked_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_eu_rate')) { + $data['shipping_royal_mail_international_tracked_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_eu_rate'] = '0.02:7.16,0.06:7.76,0.1:9.84,0.25:10.44,0.5:12.18,0.75:13.92,1:15.66,1.25:17.40,1.5:19.14,1.75:20.88,2:22.62'; + } + + // International Tracked + // Non Europe + if (isset($this->request->post['shipping_royal_mail_international_tracked_non_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_non_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_non_eu_rate')) { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_non_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.5:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + // International Tracked + // World Zones 1 + if (isset($this->request->post['shipping_royal_mail_international_tracked_zone_1_rate'])) { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_tracked_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_zone_1_rate')) { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_tracked_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = '0.02:5.97,0.06:6.47,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + // International Tracked + // World Zones 2 + if (isset($this->request->post['shipping_royal_mail_international_tracked_zone_2_rate'])) { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_tracked_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_zone_2_rate')) { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_tracked_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_status'])) { + $data['shipping_royal_mail_international_tracked_status'] = $this->request->post['shipping_royal_mail_international_tracked_status']; + } else { + $data['shipping_royal_mail_international_tracked_status'] = $this->config->get('shipping_royal_mail_international_tracked_status'); + } + + // International Signed + // Europe + if (isset($this->request->post['shipping_royal_mail_international_signed_eu_rate'])) { + $data['shipping_royal_mail_international_signed_eu_rate'] = $this->request->post['shipping_royal_mail_international_signed_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_eu_rate')) { + $data['shipping_royal_mail_international_signed_eu_rate'] = $this->config->get('shipping_royal_mail_international_signed_eu_rate'); + } else { + $data['shipping_royal_mail_international_signed_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.5:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + // International Signed + // World Zones 1 + if (isset($this->request->post['shipping_royal_mail_international_signed_zone_1_rate'])) { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_signed_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_zone_1_rate')) { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_signed_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = '0.02:6.28,0.06:7.15,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + // International Signed + // World Zones 2 + if (isset($this->request->post['shipping_royal_mail_international_signed_zone_2_rate'])) { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_signed_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_zone_2_rate')) { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_signed_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_signed_status'])) { + $data['shipping_royal_mail_international_signed_status'] = $this->request->post['shipping_royal_mail_international_signed_status']; + } else { + $data['shipping_royal_mail_international_signed_status'] = $this->config->get('shipping_royal_mail_international_signed_status'); + } + + // International Economy + if (isset($this->request->post['shipping_royal_mail_international_economy_rate'])) { + $data['shipping_royal_mail_international_economy_rate'] = $this->request->post['shipping_royal_mail_international_economy_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_economy_rate')) { + $data['shipping_royal_mail_international_economy_rate'] = $this->config->get('shipping_royal_mail_international_economy_rate'); + } else { + $data['shipping_royal_mail_international_economy_rate'] = '0.02:0.81,0.06:1.43,0.1:2.80,0.25:3.65,0.5:5.10,0.75:6.55,1:8.00,1.25:9.45,1.5:10.90,1.75:12.35,2:13.80'; + } + + if (isset($this->request->post['shipping_royal_mail_international_economy_status'])) { + $data['shipping_royal_mail_international_economy_status'] = $this->request->post['shipping_royal_mail_international_economy_status']; + } else { + $data['shipping_royal_mail_international_economy_status'] = $this->config->get('shipping_royal_mail_international_economy_status'); + } + + if (isset($this->request->post['shipping_royal_mail_display_weight'])) { + $data['shipping_royal_mail_display_weight'] = $this->request->post['shipping_royal_mail_display_weight']; + } else { + $data['shipping_royal_mail_display_weight'] = $this->config->get('shipping_royal_mail_display_weight'); + } + + if (isset($this->request->post['shipping_royal_mail_display_insurance'])) { + $data['shipping_royal_mail_display_insurance'] = $this->request->post['shipping_royal_mail_display_insurance']; + } else { + $data['shipping_royal_mail_display_insurance'] = $this->config->get('shipping_royal_mail_display_insurance'); + } + + if (isset($this->request->post['shipping_royal_mail_weight_class_id'])) { + $data['shipping_royal_mail_weight_class_id'] = $this->request->post['shipping_royal_mail_weight_class_id']; + } else { + $data['shipping_royal_mail_weight_class_id'] = $this->config->get('shipping_royal_mail_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_royal_mail_tax_class_id'])) { + $data['shipping_royal_mail_tax_class_id'] = $this->request->post['shipping_royal_mail_tax_class_id']; + } else { + $data['shipping_royal_mail_tax_class_id'] = $this->config->get('shipping_royal_mail_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_royal_mail_geo_zone_id'])) { + $data['shipping_royal_mail_geo_zone_id'] = $this->request->post['shipping_royal_mail_geo_zone_id']; + } else { + $data['shipping_royal_mail_geo_zone_id'] = $this->config->get('shipping_royal_mail_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_royal_mail_status'])) { + $data['shipping_royal_mail_status'] = $this->request->post['shipping_royal_mail_status']; + } else { + $data['shipping_royal_mail_status'] = $this->config->get('shipping_royal_mail_status'); + } + + if (isset($this->request->post['shipping_royal_mail_sort_order'])) { + $data['shipping_royal_mail_sort_order'] = $this->request->post['shipping_royal_mail_sort_order']; + } else { + $data['shipping_royal_mail_sort_order'] = $this->config->get('shipping_royal_mail_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/royal_mail', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/royal_mail')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/ups.php b/public/admin/controller/extension/shipping/ups.php new file mode 100644 index 0000000..dfb0e4a --- /dev/null +++ b/public/admin/controller/extension/shipping/ups.php @@ -0,0 +1,744 @@ +<?php +class ControllerExtensionShippingUPS extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/ups'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_ups', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['city'])) { + $data['error_city'] = $this->error['city']; + } else { + $data['error_city'] = ''; + } + + if (isset($this->error['state'])) { + $data['error_state'] = $this->error['state']; + } else { + $data['error_state'] = ''; + } + + if (isset($this->error['country'])) { + $data['error_country'] = $this->error['country']; + } else { + $data['error_country'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/ups', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/ups', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_ups_key'])) { + $data['shipping_ups_key'] = $this->request->post['shipping_ups_key']; + } else { + $data['shipping_ups_key'] = $this->config->get('shipping_ups_key'); + } + + if (isset($this->request->post['shipping_ups_username'])) { + $data['shipping_ups_username'] = $this->request->post['shipping_ups_username']; + } else { + $data['shipping_ups_username'] = $this->config->get('shipping_ups_username'); + } + + if (isset($this->request->post['shipping_ups_password'])) { + $data['shipping_ups_password'] = $this->request->post['shipping_ups_password']; + } else { + $data['shipping_ups_password'] = $this->config->get('shipping_ups_password'); + } + + if (isset($this->request->post['shipping_ups_pickup'])) { + $data['shipping_ups_pickup'] = $this->request->post['shipping_ups_pickup']; + } else { + $data['shipping_ups_pickup'] = $this->config->get('shipping_ups_pickup'); + } + + $data['pickups'] = array(); + + $data['pickups'][] = array( + 'value' => '01', + 'text' => $this->language->get('text_daily_pickup') + ); + + $data['pickups'][] = array( + 'value' => '03', + 'text' => $this->language->get('text_customer_counter') + ); + + $data['pickups'][] = array( + 'value' => '06', + 'text' => $this->language->get('text_one_time_pickup') + ); + + $data['pickups'][] = array( + 'value' => '07', + 'text' => $this->language->get('text_on_call_air_pickup') + ); + + $data['pickups'][] = array( + 'value' => '19', + 'text' => $this->language->get('text_letter_center') + ); + + $data['pickups'][] = array( + 'value' => '20', + 'text' => $this->language->get('text_air_service_center') + ); + + $data['pickups'][] = array( + 'value' => '11', + 'text' => $this->language->get('text_suggested_retail_rates') + ); + + if (isset($this->request->post['shipping_ups_packaging'])) { + $data['shipping_ups_packaging'] = $this->request->post['shipping_ups_packaging']; + } else { + $data['shipping_ups_packaging'] = $this->config->get('shipping_ups_packaging'); + } + + $data['packages'] = array(); + + $data['packages'][] = array( + 'value' => '02', + 'text' => $this->language->get('text_package') + ); + + $data['packages'][] = array( + 'value' => '01', + 'text' => $this->language->get('text_ups_letter') + ); + + $data['packages'][] = array( + 'value' => '03', + 'text' => $this->language->get('text_ups_tube') + ); + + $data['packages'][] = array( + 'value' => '04', + 'text' => $this->language->get('text_ups_pak') + ); + + $data['packages'][] = array( + 'value' => '21', + 'text' => $this->language->get('text_ups_express_box') + ); + + $data['packages'][] = array( + 'value' => '24', + 'text' => $this->language->get('text_ups_25kg_box') + ); + + $data['packages'][] = array( + 'value' => '25', + 'text' => $this->language->get('text_ups_10kg_box') + ); + + if (isset($this->request->post['shipping_ups_classification'])) { + $data['shipping_ups_classification'] = $this->request->post['shipping_ups_classification']; + } else { + $data['shipping_ups_classification'] = $this->config->get('shipping_ups_classification'); + } + + $data['classifications'][] = array( + 'value' => '01', + 'text' => '01' + ); + + $data['classifications'][] = array( + 'value' => '03', + 'text' => '03' + ); + + $data['classifications'][] = array( + 'value' => '04', + 'text' => '04' + ); + + if (isset($this->request->post['shipping_ups_origin'])) { + $data['shipping_ups_origin'] = $this->request->post['shipping_ups_origin']; + } else { + $data['shipping_ups_origin'] = $this->config->get('shipping_ups_origin'); + } + + $data['origins'] = array(); + + $data['origins'][] = array( + 'value' => 'US', + 'text' => $this->language->get('text_us') + ); + + $data['origins'][] = array( + 'value' => 'CA', + 'text' => $this->language->get('text_ca') + ); + + $data['origins'][] = array( + 'value' => 'EU', + 'text' => $this->language->get('text_eu') + ); + + $data['origins'][] = array( + 'value' => 'PR', + 'text' => $this->language->get('text_pr') + ); + + $data['origins'][] = array( + 'value' => 'MX', + 'text' => $this->language->get('text_mx') + ); + + $data['origins'][] = array( + 'value' => 'other', + 'text' => $this->language->get('text_other') + ); + + if (isset($this->request->post['shipping_ups_city'])) { + $data['shipping_ups_city'] = $this->request->post['shipping_ups_city']; + } else { + $data['shipping_ups_city'] = $this->config->get('shipping_ups_city'); + } + + if (isset($this->request->post['shipping_ups_state'])) { + $data['shipping_ups_state'] = $this->request->post['shipping_ups_state']; + } else { + $data['shipping_ups_state'] = $this->config->get('shipping_ups_state'); + } + + if (isset($this->request->post['shipping_ups_country'])) { + $data['shipping_ups_country'] = $this->request->post['shipping_ups_country']; + } else { + $data['shipping_ups_country'] = $this->config->get('shipping_ups_country'); + } + + if (isset($this->request->post['shipping_ups_postcode'])) { + $data['shipping_ups_postcode'] = $this->request->post['shipping_ups_postcode']; + } else { + $data['shipping_ups_postcode'] = $this->config->get('shipping_ups_postcode'); + } + + if (isset($this->request->post['shipping_ups_test'])) { + $data['shipping_ups_test'] = $this->request->post['shipping_ups_test']; + } else { + $data['shipping_ups_test'] = $this->config->get('shipping_ups_test'); + } + + if (isset($this->request->post['shipping_ups_quote_type'])) { + $data['shipping_ups_quote_type'] = $this->request->post['shipping_ups_quote_type']; + } else { + $data['shipping_ups_quote_type'] = $this->config->get('shipping_ups_quote_type'); + } + + $data['quote_types'] = array(); + + $data['quote_types'][] = array( + 'value' => 'residential', + 'text' => $this->language->get('text_residential') + ); + + $data['quote_types'][] = array( + 'value' => 'commercial', + 'text' => $this->language->get('text_commercial') + ); + + // US + if (isset($this->request->post['shipping_ups_us_01'])) { + $data['shipping_ups_us_01'] = $this->request->post['shipping_ups_us_01']; + } else { + $data['shipping_ups_us_01'] = $this->config->get('shipping_ups_us_01'); + } + + if (isset($this->request->post['shipping_ups_us_02'])) { + $data['shipping_ups_us_02'] = $this->request->post['shipping_ups_us_02']; + } else { + $data['shipping_ups_us_02'] = $this->config->get('shipping_ups_us_02'); + } + + if (isset($this->request->post['shipping_ups_us_03'])) { + $data['shipping_ups_us_03'] = $this->request->post['shipping_ups_us_03']; + } else { + $data['shipping_ups_us_03'] = $this->config->get('shipping_ups_us_03'); + } + + if (isset($this->request->post['shipping_ups_us_07'])) { + $data['shipping_ups_us_07'] = $this->request->post['shipping_ups_us_07']; + } else { + $data['shipping_ups_us_07'] = $this->config->get('shipping_ups_us_07'); + } + + if (isset($this->request->post['shipping_ups_us_08'])) { + $data['shipping_ups_us_08'] = $this->request->post['shipping_ups_us_08']; + } else { + $data['shipping_ups_us_08'] = $this->config->get('shipping_ups_us_08'); + } + + if (isset($this->request->post['shipping_ups_us_11'])) { + $data['shipping_ups_us_11'] = $this->request->post['shipping_ups_us_11']; + } else { + $data['shipping_ups_us_11'] = $this->config->get('shipping_ups_us_11'); + } + + if (isset($this->request->post['shipping_ups_us_12'])) { + $data['shipping_ups_us_12'] = $this->request->post['shipping_ups_us_12']; + } else { + $data['shipping_ups_us_12'] = $this->config->get('shipping_ups_us_12'); + } + + if (isset($this->request->post['shipping_ups_us_13'])) { + $data['shipping_ups_us_13'] = $this->request->post['shipping_ups_us_13']; + } else { + $data['shipping_ups_us_13'] = $this->config->get('shipping_ups_us_13'); + } + + if (isset($this->request->post['shipping_ups_us_14'])) { + $data['shipping_ups_us_14'] = $this->request->post['shipping_ups_us_14']; + } else { + $data['shipping_ups_us_14'] = $this->config->get('shipping_ups_us_14'); + } + + if (isset($this->request->post['shipping_ups_us_54'])) { + $data['shipping_ups_us_54'] = $this->request->post['shipping_ups_us_54']; + } else { + $data['shipping_ups_us_54'] = $this->config->get('shipping_ups_us_54'); + } + + if (isset($this->request->post['shipping_ups_us_59'])) { + $data['shipping_ups_us_59'] = $this->request->post['shipping_ups_us_59']; + } else { + $data['shipping_ups_us_59'] = $this->config->get('shipping_ups_us_59'); + } + + if (isset($this->request->post['shipping_ups_us_65'])) { + $data['shipping_ups_us_65'] = $this->request->post['shipping_ups_us_65']; + } else { + $data['shipping_ups_us_65'] = $this->config->get('shipping_ups_us_65'); + } + + // Puerto Rico + if (isset($this->request->post['shipping_ups_pr_01'])) { + $data['shipping_ups_pr_01'] = $this->request->post['shipping_ups_pr_01']; + } else { + $data['shipping_ups_pr_01'] = $this->config->get('shipping_ups_pr_01'); + } + + if (isset($this->request->post['shipping_ups_pr_02'])) { + $data['shipping_ups_pr_02'] = $this->request->post['shipping_ups_pr_02']; + } else { + $data['shipping_ups_pr_02'] = $this->config->get('shipping_ups_pr_02'); + } + + if (isset($this->request->post['shipping_ups_pr_03'])) { + $data['shipping_ups_pr_03'] = $this->request->post['shipping_ups_pr_03']; + } else { + $data['shipping_ups_pr_03'] = $this->config->get('shipping_ups_pr_03'); + } + + if (isset($this->request->post['shipping_ups_pr_07'])) { + $data['shipping_ups_pr_07'] = $this->request->post['shipping_ups_pr_07']; + } else { + $data['shipping_ups_pr_07'] = $this->config->get('shipping_ups_pr_07'); + } + + if (isset($this->request->post['shipping_ups_pr_08'])) { + $data['shipping_ups_pr_08'] = $this->request->post['shipping_ups_pr_08']; + } else { + $data['shipping_ups_pr_08'] = $this->config->get('shipping_ups_pr_08'); + } + + if (isset($this->request->post['shipping_ups_pr_14'])) { + $data['shipping_ups_pr_14'] = $this->request->post['shipping_ups_pr_14']; + } else { + $data['shipping_ups_pr_14'] = $this->config->get('shipping_ups_pr_14'); + } + + if (isset($this->request->post['shipping_ups_pr_54'])) { + $data['shipping_ups_pr_54'] = $this->request->post['shipping_ups_pr_54']; + } else { + $data['shipping_ups_pr_54'] = $this->config->get('shipping_ups_pr_54'); + } + + if (isset($this->request->post['shipping_ups_pr_65'])) { + $data['shipping_ups_pr_65'] = $this->request->post['shipping_ups_pr_65']; + } else { + $data['shipping_ups_pr_65'] = $this->config->get('shipping_ups_pr_65'); + } + + // Canada + if (isset($this->request->post['shipping_ups_ca_01'])) { + $data['shipping_ups_ca_01'] = $this->request->post['shipping_ups_ca_01']; + } else { + $data['shipping_ups_ca_01'] = $this->config->get('shipping_ups_ca_01'); + } + + if (isset($this->request->post['shipping_ups_ca_02'])) { + $data['shipping_ups_ca_02'] = $this->request->post['shipping_ups_ca_02']; + } else { + $data['shipping_ups_ca_02'] = $this->config->get('shipping_ups_ca_02'); + } + + if (isset($this->request->post['shipping_ups_ca_07'])) { + $data['shipping_ups_ca_07'] = $this->request->post['shipping_ups_ca_07']; + } else { + $data['shipping_ups_ca_07'] = $this->config->get('shipping_ups_ca_07'); + } + + if (isset($this->request->post['shipping_ups_ca_08'])) { + $data['shipping_ups_ca_08'] = $this->request->post['shipping_ups_ca_08']; + } else { + $data['shipping_ups_ca_08'] = $this->config->get('shipping_ups_ca_08'); + } + + if (isset($this->request->post['shipping_ups_ca_11'])) { + $data['shipping_ups_ca_11'] = $this->request->post['shipping_ups_ca_11']; + } else { + $data['shipping_ups_ca_11'] = $this->config->get('shipping_ups_ca_11'); + } + + if (isset($this->request->post['shipping_ups_ca_12'])) { + $data['shipping_ups_ca_12'] = $this->request->post['shipping_ups_ca_12']; + } else { + $data['shipping_ups_ca_12'] = $this->config->get('shipping_ups_ca_12'); + } + + if (isset($this->request->post['shipping_ups_ca_13'])) { + $data['shipping_ups_ca_13'] = $this->request->post['shipping_ups_ca_13']; + } else { + $data['shipping_ups_ca_13'] = $this->config->get('shipping_ups_ca_13'); + } + + if (isset($this->request->post['shipping_ups_ca_14'])) { + $data['shipping_ups_ca_14'] = $this->request->post['shipping_ups_ca_14']; + } else { + $data['shipping_ups_ca_14'] = $this->config->get('shipping_ups_ca_14'); + } + + if (isset($this->request->post['shipping_ups_ca_54'])) { + $data['shipping_ups_ca_54'] = $this->request->post['shipping_ups_ca_54']; + } else { + $data['shipping_ups_ca_54'] = $this->config->get('shipping_ups_ca_54'); + } + + if (isset($this->request->post['shipping_ups_ca_65'])) { + $data['shipping_ups_ca_65'] = $this->request->post['shipping_ups_ca_65']; + } else { + $data['shipping_ups_ca_65'] = $this->config->get('shipping_ups_ca_65'); + } + + // Mexico + if (isset($this->request->post['shipping_ups_mx_07'])) { + $data['shipping_ups_mx_07'] = $this->request->post['shipping_ups_mx_07']; + } else { + $data['shipping_ups_mx_07'] = $this->config->get('shipping_ups_mx_07'); + } + + if (isset($this->request->post['shipping_ups_mx_08'])) { + $data['shipping_ups_mx_08'] = $this->request->post['shipping_ups_mx_08']; + } else { + $data['shipping_ups_mx_08'] = $this->config->get('shipping_ups_mx_08'); + } + + if (isset($this->request->post['shipping_ups_mx_54'])) { + $data['shipping_ups_mx_54'] = $this->request->post['shipping_ups_mx_54']; + } else { + $data['shipping_ups_mx_54'] = $this->config->get('shipping_ups_mx_54'); + } + + if (isset($this->request->post['shipping_ups_mx_65'])) { + $data['shipping_ups_mx_65'] = $this->request->post['shipping_ups_mx_65']; + } else { + $data['shipping_ups_mx_65'] = $this->config->get('shipping_ups_mx_65'); + } + + // EU + if (isset($this->request->post['shipping_ups_eu_07'])) { + $data['shipping_ups_eu_07'] = $this->request->post['shipping_ups_eu_07']; + } else { + $data['shipping_ups_eu_07'] = $this->config->get('shipping_ups_eu_07'); + } + + if (isset($this->request->post['shipping_ups_eu_08'])) { + $data['shipping_ups_eu_08'] = $this->request->post['shipping_ups_eu_08']; + } else { + $data['shipping_ups_eu_08'] = $this->config->get('shipping_ups_eu_08'); + } + + if (isset($this->request->post['shipping_ups_eu_11'])) { + $data['shipping_ups_eu_11'] = $this->request->post['shipping_ups_eu_11']; + } else { + $data['shipping_ups_eu_11'] = $this->config->get('shipping_ups_eu_11'); + } + + if (isset($this->request->post['shipping_ups_eu_54'])) { + $data['shipping_ups_eu_54'] = $this->request->post['shipping_ups_eu_54']; + } else { + $data['shipping_ups_eu_54'] = $this->config->get('shipping_ups_eu_54'); + } + + if (isset($this->request->post['shipping_ups_eu_65'])) { + $data['shipping_ups_eu_65'] = $this->request->post['shipping_ups_eu_65']; + } else { + $data['shipping_ups_eu_65'] = $this->config->get('shipping_ups_eu_65'); + } + + if (isset($this->request->post['shipping_ups_eu_82'])) { + $data['shipping_ups_eu_82'] = $this->request->post['shipping_ups_eu_82']; + } else { + $data['shipping_ups_eu_82'] = $this->config->get('shipping_ups_eu_82'); + } + + if (isset($this->request->post['shipping_ups_eu_83'])) { + $data['shipping_ups_eu_83'] = $this->request->post['shipping_ups_eu_83']; + } else { + $data['shipping_ups_eu_83'] = $this->config->get('shipping_ups_eu_83'); + } + + if (isset($this->request->post['shipping_ups_eu_84'])) { + $data['shipping_ups_eu_84'] = $this->request->post['shipping_ups_eu_84']; + } else { + $data['shipping_ups_eu_84'] = $this->config->get('shipping_ups_eu_84'); + } + + if (isset($this->request->post['shipping_ups_eu_85'])) { + $data['shipping_ups_eu_85'] = $this->request->post['shipping_ups_eu_85']; + } else { + $data['shipping_ups_eu_85'] = $this->config->get('shipping_ups_eu_85'); + } + + if (isset($this->request->post['shipping_ups_eu_86'])) { + $data['shipping_ups_eu_86'] = $this->request->post['shipping_ups_eu_86']; + } else { + $data['shipping_ups_eu_86'] = $this->config->get('shipping_ups_eu_86'); + } + + // Other + if (isset($this->request->post['shipping_ups_other_07'])) { + $data['shipping_ups_other_07'] = $this->request->post['shipping_ups_other_07']; + } else { + $data['shipping_ups_other_07'] = $this->config->get('shipping_ups_other_07'); + } + + if (isset($this->request->post['shipping_ups_other_08'])) { + $data['shipping_ups_other_08'] = $this->request->post['shipping_ups_other_08']; + } else { + $data['shipping_ups_other_08'] = $this->config->get('shipping_ups_other_08'); + } + + if (isset($this->request->post['shipping_ups_other_11'])) { + $data['shipping_ups_other_11'] = $this->request->post['shipping_ups_other_11']; + } else { + $data['shipping_ups_other_11'] = $this->config->get('shipping_ups_other_11'); + } + + if (isset($this->request->post['shipping_ups_other_54'])) { + $data['shipping_ups_other_54'] = $this->request->post['shipping_ups_other_54']; + } else { + $data['shipping_ups_other_54'] = $this->config->get('shipping_ups_other_54'); + } + + if (isset($this->request->post['shipping_ups_other_65'])) { + $data['shipping_ups_other_65'] = $this->request->post['shipping_ups_other_65']; + } else { + $data['shipping_ups_other_65'] = $this->config->get('shipping_ups_other_65'); + } + + if (isset($this->request->post['shipping_ups_display_weight'])) { + $data['shipping_ups_display_weight'] = $this->request->post['shipping_ups_display_weight']; + } else { + $data['shipping_ups_display_weight'] = $this->config->get('shipping_ups_display_weight'); + } + + if (isset($this->request->post['shipping_ups_insurance'])) { + $data['shipping_ups_insurance'] = $this->request->post['shipping_ups_insurance']; + } else { + $data['shipping_ups_insurance'] = $this->config->get('shipping_ups_insurance'); + } + + if (isset($this->request->post['shipping_ups_weight_class_id'])) { + $data['shipping_ups_weight_class_id'] = $this->request->post['shipping_ups_weight_class_id']; + } else { + $data['shipping_ups_weight_class_id'] = $this->config->get('shipping_ups_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_ups_length_code'])) { + $data['shipping_ups_length_code'] = $this->request->post['shipping_ups_length_code']; + } else { + $data['shipping_ups_length_code'] = $this->config->get('shipping_ups_length_code'); + } + + if (isset($this->request->post['shipping_ups_length_class_id'])) { + $data['shipping_ups_length_class_id'] = $this->request->post['shipping_ups_length_class_id']; + } else { + $data['shipping_ups_length_class_id'] = $this->config->get('shipping_ups_length_class_id'); + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['shipping_ups_length'])) { + $data['shipping_ups_length'] = $this->request->post['shipping_ups_length']; + } else { + $data['shipping_ups_length'] = $this->config->get('shipping_ups_length'); + } + + if (isset($this->request->post['shipping_ups_width'])) { + $data['shipping_ups_width'] = $this->request->post['shipping_ups_width']; + } else { + $data['shipping_ups_width'] = $this->config->get('shipping_ups_width'); + } + + if (isset($this->request->post['shipping_ups_height'])) { + $data['shipping_ups_height'] = $this->request->post['shipping_ups_height']; + } else { + $data['shipping_ups_height'] = $this->config->get('shipping_ups_height'); + } + + if (isset($this->request->post['shipping_ups_tax_class_id'])) { + $data['shipping_ups_tax_class_id'] = $this->request->post['shipping_ups_tax_class_id']; + } else { + $data['shipping_ups_tax_class_id'] = $this->config->get('shipping_ups_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_ups_geo_zone_id'])) { + $data['shipping_ups_geo_zone_id'] = $this->request->post['shipping_ups_geo_zone_id']; + } else { + $data['shipping_ups_geo_zone_id'] = $this->config->get('shipping_ups_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_ups_status'])) { + $data['shipping_ups_status'] = $this->request->post['shipping_ups_status']; + } else { + $data['shipping_ups_status'] = $this->config->get('shipping_ups_status'); + } + + if (isset($this->request->post['shipping_ups_sort_order'])) { + $data['shipping_ups_sort_order'] = $this->request->post['shipping_ups_sort_order']; + } else { + $data['shipping_ups_sort_order'] = $this->config->get('shipping_ups_sort_order'); + } + + if (isset($this->request->post['shipping_ups_debug'])) { + $data['shipping_ups_debug'] = $this->request->post['shipping_ups_debug']; + } else { + $data['shipping_ups_debug'] = $this->config->get('shipping_ups_debug'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/ups', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/ups')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_ups_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['shipping_ups_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['shipping_ups_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['shipping_ups_city']) { + $this->error['city'] = $this->language->get('error_city'); + } + + if (!$this->request->post['shipping_ups_state']) { + $this->error['state'] = $this->language->get('error_state'); + } + + if (!$this->request->post['shipping_ups_country']) { + $this->error['country'] = $this->language->get('error_country'); + } + + if (empty($this->request->post['shipping_ups_length'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + if (empty($this->request->post['shipping_ups_width'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + if (empty($this->request->post['shipping_ups_height'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/usps.php b/public/admin/controller/extension/shipping/usps.php new file mode 100644 index 0000000..503e35a --- /dev/null +++ b/public/admin/controller/extension/shipping/usps.php @@ -0,0 +1,464 @@ +<?php +class ControllerExtensionShippingUsps extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/usps'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_usps', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['user_id'])) { + $data['error_user_id'] = $this->error['user_id']; + } else { + $data['error_user_id'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_usps_user_id'])) { + $data['shipping_usps_user_id'] = $this->request->post['shipping_usps_user_id']; + } else { + $data['shipping_usps_user_id'] = $this->config->get('shipping_usps_user_id'); + } + + if (isset($this->request->post['shipping_usps_postcode'])) { + $data['shipping_usps_postcode'] = $this->request->post['shipping_usps_postcode']; + } else { + $data['shipping_usps_postcode'] = $this->config->get('shipping_usps_postcode'); + } + + if (isset($this->request->post['shipping_usps_domestic_00'])) { + $data['shipping_usps_domestic_00'] = $this->request->post['shipping_usps_domestic_00']; + } else { + $data['shipping_usps_domestic_00'] = $this->config->get('shipping_usps_domestic_00'); + } + + if (isset($this->request->post['shipping_usps_domestic_01'])) { + $data['shipping_usps_domestic_01'] = $this->request->post['shipping_usps_domestic_01']; + } else { + $data['shipping_usps_domestic_01'] = $this->config->get('shipping_usps_domestic_01'); + } + + if (isset($this->request->post['shipping_usps_domestic_02'])) { + $data['shipping_usps_domestic_02'] = $this->request->post['shipping_usps_domestic_02']; + } else { + $data['shipping_usps_domestic_02'] = $this->config->get('shipping_usps_domestic_02'); + } + + if (isset($this->request->post['shipping_usps_domestic_03'])) { + $data['shipping_usps_domestic_03'] = $this->request->post['shipping_usps_domestic_03']; + } else { + $data['shipping_usps_domestic_03'] = $this->config->get('shipping_usps_domestic_03'); + } + + if (isset($this->request->post['shipping_usps_domestic_1'])) { + $data['shipping_usps_domestic_1'] = $this->request->post['shipping_usps_domestic_1']; + } else { + $data['shipping_usps_domestic_1'] = $this->config->get('shipping_usps_domestic_1'); + } + + if (isset($this->request->post['shipping_usps_domestic_2'])) { + $data['shipping_usps_domestic_2'] = $this->request->post['shipping_usps_domestic_2']; + } else { + $data['shipping_usps_domestic_2'] = $this->config->get('shipping_usps_domestic_2'); + } + + if (isset($this->request->post['shipping_usps_domestic_3'])) { + $data['shipping_usps_domestic_3'] = $this->request->post['shipping_usps_domestic_3']; + } else { + $data['shipping_usps_domestic_3'] = $this->config->get('shipping_usps_domestic_3'); + } + + if (isset($this->request->post['shipping_usps_domestic_4'])) { + $data['shipping_usps_domestic_4'] = $this->request->post['shipping_usps_domestic_4']; + } else { + $data['shipping_usps_domestic_4'] = $this->config->get('shipping_usps_domestic_4'); + } + + if (isset($this->request->post['shipping_usps_domestic_5'])) { + $data['shipping_usps_domestic_5'] = $this->request->post['shipping_usps_domestic_5']; + } else { + $data['shipping_usps_domestic_5'] = $this->config->get('shipping_usps_domestic_5'); + } + + if (isset($this->request->post['shipping_usps_domestic_6'])) { + $data['shipping_usps_domestic_6'] = $this->request->post['shipping_usps_domestic_6']; + } else { + $data['shipping_usps_domestic_6'] = $this->config->get('shipping_usps_domestic_6'); + } + + if (isset($this->request->post['shipping_usps_domestic_7'])) { + $data['shipping_usps_domestic_7'] = $this->request->post['shipping_usps_domestic_7']; + } else { + $data['shipping_usps_domestic_7'] = $this->config->get('shipping_usps_domestic_7'); + } + + if (isset($this->request->post['shipping_usps_domestic_12'])) { + $data['shipping_usps_domestic_12'] = $this->request->post['shipping_usps_domestic_12']; + } else { + $data['shipping_usps_domestic_12'] = $this->config->get('shipping_usps_domestic_12'); + } + + if (isset($this->request->post['shipping_usps_domestic_13'])) { + $data['shipping_usps_domestic_13'] = $this->request->post['shipping_usps_domestic_13']; + } else { + $data['shipping_usps_domestic_13'] = $this->config->get('shipping_usps_domestic_13'); + } + + if (isset($this->request->post['shipping_usps_domestic_16'])) { + $data['shipping_usps_domestic_16'] = $this->request->post['shipping_usps_domestic_16']; + } else { + $data['shipping_usps_domestic_16'] = $this->config->get('shipping_usps_domestic_16'); + } + + if (isset($this->request->post['shipping_usps_domestic_17'])) { + $data['shipping_usps_domestic_17'] = $this->request->post['shipping_usps_domestic_17']; + } else { + $data['shipping_usps_domestic_17'] = $this->config->get('shipping_usps_domestic_17'); + } + + if (isset($this->request->post['shipping_usps_domestic_18'])) { + $data['shipping_usps_domestic_18'] = $this->request->post['shipping_usps_domestic_18']; + } else { + $data['shipping_usps_domestic_18'] = $this->config->get('shipping_usps_domestic_18'); + } + + if (isset($this->request->post['shipping_usps_domestic_19'])) { + $data['shipping_usps_domestic_19'] = $this->request->post['shipping_usps_domestic_19']; + } else { + $data['shipping_usps_domestic_19'] = $this->config->get('shipping_usps_domestic_19'); + } + + if (isset($this->request->post['shipping_usps_domestic_22'])) { + $data['shipping_usps_domestic_22'] = $this->request->post['shipping_usps_domestic_22']; + } else { + $data['shipping_usps_domestic_22'] = $this->config->get('shipping_usps_domestic_22'); + } + + if (isset($this->request->post['shipping_usps_domestic_23'])) { + $data['shipping_usps_domestic_23'] = $this->request->post['shipping_usps_domestic_23']; + } else { + $data['shipping_usps_domestic_23'] = $this->config->get('shipping_usps_domestic_23'); + } + + if (isset($this->request->post['shipping_usps_domestic_25'])) { + $data['shipping_usps_domestic_25'] = $this->request->post['shipping_usps_domestic_25']; + } else { + $data['shipping_usps_domestic_25'] = $this->config->get('shipping_usps_domestic_25'); + } + + if (isset($this->request->post['shipping_usps_domestic_27'])) { + $data['shipping_usps_domestic_27'] = $this->request->post['shipping_usps_domestic_27']; + } else { + $data['shipping_usps_domestic_27'] = $this->config->get('shipping_usps_domestic_27'); + } + + if (isset($this->request->post['shipping_usps_domestic_28'])) { + $data['shipping_usps_domestic_28'] = $this->request->post['shipping_usps_domestic_28']; + } else { + $data['shipping_usps_domestic_28'] = $this->config->get('shipping_usps_domestic_28'); + } + + if (isset($this->request->post['shipping_usps_international_1'])) { + $data['shipping_usps_international_1'] = $this->request->post['shipping_usps_international_1']; + } else { + $data['shipping_usps_international_1'] = $this->config->get('shipping_usps_international_1'); + } + + if (isset($this->request->post['shipping_usps_international_2'])) { + $data['shipping_usps_international_2'] = $this->request->post['shipping_usps_international_2']; + } else { + $data['shipping_usps_international_2'] = $this->config->get('shipping_usps_international_2'); + } + + if (isset($this->request->post['shipping_usps_international_4'])) { + $data['shipping_usps_international_4'] = $this->request->post['shipping_usps_international_4']; + } else { + $data['shipping_usps_international_4'] = $this->config->get('shipping_usps_international_4'); + } + + if (isset($this->request->post['shipping_usps_international_5'])) { + $data['shipping_usps_international_5'] = $this->request->post['shipping_usps_international_5']; + } else { + $data['shipping_usps_international_5'] = $this->config->get('shipping_usps_international_5'); + } + + if (isset($this->request->post['shipping_usps_international_6'])) { + $data['shipping_usps_international_6'] = $this->request->post['shipping_usps_international_6']; + } else { + $data['shipping_usps_international_6'] = $this->config->get('shipping_usps_international_6'); + } + + if (isset($this->request->post['shipping_usps_international_7'])) { + $data['shipping_usps_international_7'] = $this->request->post['shipping_usps_international_7']; + } else { + $data['shipping_usps_international_7'] = $this->config->get('shipping_usps_international_7'); + } + + if (isset($this->request->post['shipping_usps_international_8'])) { + $data['shipping_usps_international_8'] = $this->request->post['shipping_usps_international_8']; + } else { + $data['shipping_usps_international_8'] = $this->config->get('shipping_usps_international_8'); + } + + if (isset($this->request->post['shipping_usps_international_9'])) { + $data['shipping_usps_international_9'] = $this->request->post['shipping_usps_international_9']; + } else { + $data['shipping_usps_international_9'] = $this->config->get('shipping_usps_international_9'); + } + + if (isset($this->request->post['shipping_usps_international_10'])) { + $data['shipping_usps_international_10'] = $this->request->post['shipping_usps_international_10']; + } else { + $data['shipping_usps_international_10'] = $this->config->get('shipping_usps_international_10'); + } + + if (isset($this->request->post['shipping_usps_international_11'])) { + $data['shipping_usps_international_11'] = $this->request->post['shipping_usps_international_11']; + } else { + $data['shipping_usps_international_11'] = $this->config->get('shipping_usps_international_11'); + } + + if (isset($this->request->post['shipping_usps_international_12'])) { + $data['shipping_usps_international_12'] = $this->request->post['shipping_usps_international_12']; + } else { + $data['shipping_usps_international_12'] = $this->config->get('shipping_usps_international_12'); + } + + if (isset($this->request->post['shipping_usps_international_13'])) { + $data['shipping_usps_international_13'] = $this->request->post['shipping_usps_international_13']; + } else { + $data['shipping_usps_international_13'] = $this->config->get('shipping_usps_international_13'); + } + + if (isset($this->request->post['shipping_usps_international_14'])) { + $data['shipping_usps_international_14'] = $this->request->post['shipping_usps_international_14']; + } else { + $data['shipping_usps_international_14'] = $this->config->get('shipping_usps_international_14'); + } + + if (isset($this->request->post['shipping_usps_international_15'])) { + $data['shipping_usps_international_15'] = $this->request->post['shipping_usps_international_15']; + } else { + $data['shipping_usps_international_15'] = $this->config->get('shipping_usps_international_15'); + } + + if (isset($this->request->post['shipping_usps_international_16'])) { + $data['shipping_usps_international_16'] = $this->request->post['shipping_usps_international_16']; + } else { + $data['shipping_usps_international_16'] = $this->config->get('shipping_usps_international_16'); + } + + if (isset($this->request->post['shipping_usps_international_21'])) { + $data['shipping_usps_international_21'] = $this->request->post['shipping_usps_international_21']; + } else { + $data['shipping_usps_international_21'] = $this->config->get('shipping_usps_international_21'); + } + + if (isset($this->request->post['shipping_usps_size'])) { + $data['shipping_usps_size'] = $this->request->post['shipping_usps_size']; + } else { + $data['shipping_usps_size'] = $this->config->get('shipping_usps_size'); + } + + $data['sizes'] = array(); + + $data['sizes'][] = array( + 'text' => $this->language->get('text_regular'), + 'value' => 'REGULAR' + ); + + $data['sizes'][] = array( + 'text' => $this->language->get('text_large'), + 'value' => 'LARGE' + ); + + if (isset($this->request->post['shipping_usps_container'])) { + $data['shipping_usps_container'] = $this->request->post['shipping_usps_container']; + } else { + $data['shipping_usps_container'] = $this->config->get('shipping_usps_container'); + } + + $data['containers'] = array(); + + $data['containers'][] = array( + 'text' => $this->language->get('text_rectangular'), + 'value' => 'RECTANGULAR' + ); + + $data['containers'][] = array( + 'text' => $this->language->get('text_non_rectangular'), + 'value' => 'NONRECTANGULAR' + ); + + $data['containers'][] = array( + 'text' => $this->language->get('text_variable'), + 'value' => 'VARIABLE' + ); + + if (isset($this->request->post['shipping_usps_machinable'])) { + $data['shipping_usps_machinable'] = $this->request->post['shipping_usps_machinable']; + } else { + $data['shipping_usps_machinable'] = $this->config->get('shipping_usps_machinable'); + } + + if (isset($this->request->post['shipping_usps_length'])) { + $data['shipping_usps_length'] = $this->request->post['shipping_usps_length']; + } else { + $data['shipping_usps_length'] = $this->config->get('shipping_usps_length'); + } + + if (isset($this->request->post['shipping_usps_width'])) { + $data['shipping_usps_width'] = $this->request->post['shipping_usps_width']; + } else { + $data['shipping_usps_width'] = $this->config->get('shipping_usps_width'); + } + + if (isset($this->request->post['shipping_usps_height'])) { + $data['shipping_usps_height'] = $this->request->post['shipping_usps_height']; + } else { + $data['shipping_usps_height'] = $this->config->get('shipping_usps_height'); + } + + if (isset($this->request->post['shipping_usps_display_time'])) { + $data['shipping_usps_display_time'] = $this->request->post['shipping_usps_display_time']; + } else { + $data['shipping_usps_display_time'] = $this->config->get('shipping_usps_display_time'); + } + + if (isset($this->request->post['shipping_usps_display_weight'])) { + $data['shipping_usps_display_weight'] = $this->request->post['shipping_usps_display_weight']; + } else { + $data['shipping_usps_display_weight'] = $this->config->get('shipping_usps_display_weight'); + } + + if (isset($this->request->post['shipping_usps_weight_class_id'])) { + $data['shipping_usps_weight_class_id'] = $this->request->post['shipping_usps_weight_class_id']; + } else { + $data['shipping_usps_weight_class_id'] = $this->config->get('shipping_usps_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_usps_tax_class_id'])) { + $data['shipping_usps_tax_class_id'] = $this->request->post['shipping_usps_tax_class_id']; + } else { + $data['shipping_usps_tax_class_id'] = $this->config->get('shipping_usps_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_usps_geo_zone_id'])) { + $data['shipping_usps_geo_zone_id'] = $this->request->post['shipping_usps_geo_zone_id']; + } else { + $data['shipping_usps_geo_zone_id'] = $this->config->get('shipping_usps_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_usps_debug'])) { + $data['shipping_usps_debug'] = $this->request->post['shipping_usps_debug']; + } else { + $data['shipping_usps_debug'] = $this->config->get('shipping_usps_debug'); + } + + if (isset($this->request->post['shipping_usps_status'])) { + $data['shipping_usps_status'] = $this->request->post['shipping_usps_status']; + } else { + $data['shipping_usps_status'] = $this->config->get('shipping_usps_status'); + } + + if (isset($this->request->post['shipping_usps_sort_order'])) { + $data['shipping_usps_sort_order'] = $this->request->post['shipping_usps_sort_order']; + } else { + $data['shipping_usps_sort_order'] = $this->config->get('shipping_usps_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/usps', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/usps')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_usps_user_id']) { + $this->error['user_id'] = $this->language->get('error_user_id'); + } + + if (!$this->request->post['shipping_usps_postcode']) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + if (!$this->request->post['shipping_usps_width']) { + $this->error['dimension'] = $this->language->get('error_width'); + } + + if (!$this->request->post['shipping_usps_height']) { + $this->error['dimension'] = $this->language->get('error_height'); + } + + if (!$this->request->post['shipping_usps_length']) { + $this->error['dimension'] = $this->language->get('error_length'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/weight.php b/public/admin/controller/extension/shipping/weight.php new file mode 100644 index 0000000..2fbda41 --- /dev/null +++ b/public/admin/controller/extension/shipping/weight.php @@ -0,0 +1,103 @@ +<?php +class ControllerExtensionShippingWeight extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/weight'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_weight', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/weight', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/weight', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + $this->load->model('localisation/geo_zone'); + + $geo_zones = $this->model_localisation_geo_zone->getGeoZones(); + + foreach ($geo_zones as $geo_zone) { + if (isset($this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate'])) { + $data['shipping_weight_geo_zone_rate'][$geo_zone['geo_zone_id']] = $this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate']; + } else { + $data['shipping_weight_geo_zone_rate'][$geo_zone['geo_zone_id']] = $this->config->get('shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate'); + } + + if (isset($this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_status'])) { + $data['shipping_weight_geo_zone_status'][$geo_zone['geo_zone_id']] = $this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_status']; + } else { + $data['shipping_weight_geo_zone_status'][$geo_zone['geo_zone_id']] = $this->config->get('shipping_weight_' . $geo_zone['geo_zone_id'] . '_status'); + } + } + + $data['geo_zones'] = $geo_zones; + + if (isset($this->request->post['shipping_weight_tax_class_id'])) { + $data['shipping_weight_tax_class_id'] = $this->request->post['shipping_weight_tax_class_id']; + } else { + $data['shipping_weight_tax_class_id'] = $this->config->get('shipping_weight_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_weight_status'])) { + $data['shipping_weight_status'] = $this->request->post['shipping_weight_status']; + } else { + $data['shipping_weight_status'] = $this->config->get('shipping_weight_status'); + } + + if (isset($this->request->post['shipping_weight_sort_order'])) { + $data['shipping_weight_sort_order'] = $this->request->post['shipping_weight_sort_order']; + } else { + $data['shipping_weight_sort_order'] = $this->config->get('shipping_weight_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/weight', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/weight')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/theme/default.php b/public/admin/controller/extension/theme/default.php new file mode 100644 index 0000000..89558e2 --- /dev/null +++ b/public/admin/controller/extension/theme/default.php @@ -0,0 +1,385 @@ +<?php +class ControllerExtensionThemeDefault extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/theme/default'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('theme_default', $this->request->post, $this->request->get['store_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['product_limit'])) { + $data['error_product_limit'] = $this->error['product_limit']; + } else { + $data['error_product_limit'] = ''; + } + + if (isset($this->error['product_description_length'])) { + $data['error_product_description_length'] = $this->error['product_description_length']; + } else { + $data['error_product_description_length'] = ''; + } + + if (isset($this->error['image_category'])) { + $data['error_image_category'] = $this->error['image_category']; + } else { + $data['error_image_category'] = ''; + } + + if (isset($this->error['image_thumb'])) { + $data['error_image_thumb'] = $this->error['image_thumb']; + } else { + $data['error_image_thumb'] = ''; + } + + if (isset($this->error['image_popup'])) { + $data['error_image_popup'] = $this->error['image_popup']; + } else { + $data['error_image_popup'] = ''; + } + + if (isset($this->error['image_product'])) { + $data['error_image_product'] = $this->error['image_product']; + } else { + $data['error_image_product'] = ''; + } + + if (isset($this->error['image_additional'])) { + $data['error_image_additional'] = $this->error['image_additional']; + } else { + $data['error_image_additional'] = ''; + } + + if (isset($this->error['image_related'])) { + $data['error_image_related'] = $this->error['image_related']; + } else { + $data['error_image_related'] = ''; + } + + if (isset($this->error['image_compare'])) { + $data['error_image_compare'] = $this->error['image_compare']; + } else { + $data['error_image_compare'] = ''; + } + + if (isset($this->error['image_wishlist'])) { + $data['error_image_wishlist'] = $this->error['image_wishlist']; + } else { + $data['error_image_wishlist'] = ''; + } + + if (isset($this->error['image_cart'])) { + $data['error_image_cart'] = $this->error['image_cart']; + } else { + $data['error_image_cart'] = ''; + } + + if (isset($this->error['image_location'])) { + $data['error_image_location'] = $this->error['image_location']; + } else { + $data['error_image_location'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/theme/default', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true) + ); + + $data['action'] = $this->url->link('extension/theme/default', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true); + + if (isset($this->request->get['store_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $setting_info = $this->model_setting_setting->getSetting('theme_default', $this->request->get['store_id']); + } + + if (isset($this->request->post['theme_default_directory'])) { + $data['theme_default_directory'] = $this->request->post['theme_default_directory']; + } elseif (isset($setting_info['theme_default_directory'])) { + $data['theme_default_directory'] = $setting_info['theme_default_directory']; + } else { + $data['theme_default_directory'] = 'default'; + } + + $data['directories'] = array(); + + $directories = glob(DIR_CATALOG . 'view/theme/*', GLOB_ONLYDIR); + + foreach ($directories as $directory) { + $data['directories'][] = basename($directory); + } + + if (isset($this->request->post['theme_default_product_limit'])) { + $data['theme_default_product_limit'] = $this->request->post['theme_default_product_limit']; + } elseif (isset($setting_info['theme_default_product_limit'])) { + $data['theme_default_product_limit'] = $setting_info['theme_default_product_limit']; + } else { + $data['theme_default_product_limit'] = 15; + } + + if (isset($this->request->post['theme_default_status'])) { + $data['theme_default_status'] = $this->request->post['theme_default_status']; + } elseif (isset($setting_info['theme_default_status'])) { + $data['theme_default_status'] = $setting_info['theme_default_status']; + } else { + $data['theme_default_status'] = ''; + } + + if (isset($this->request->post['theme_default_product_description_length'])) { + $data['theme_default_product_description_length'] = $this->request->post['theme_default_product_description_length']; + } elseif (isset($setting_info['theme_default_product_description_length'])) { + $data['theme_default_product_description_length'] = $setting_info['theme_default_product_description_length']; + } else { + $data['theme_default_product_description_length'] = 100; + } + + if (isset($this->request->post['theme_default_image_category_width'])) { + $data['theme_default_image_category_width'] = $this->request->post['theme_default_image_category_width']; + } elseif (isset($setting_info['theme_default_image_category_width'])) { + $data['theme_default_image_category_width'] = $setting_info['theme_default_image_category_width']; + } else { + $data['theme_default_image_category_width'] = 80; + } + + if (isset($this->request->post['theme_default_image_category_height'])) { + $data['theme_default_image_category_height'] = $this->request->post['theme_default_image_category_height']; + } elseif (isset($setting_info['theme_default_image_category_height'])) { + $data['theme_default_image_category_height'] = $setting_info['theme_default_image_category_height']; + } else { + $data['theme_default_image_category_height'] = 80; + } + + if (isset($this->request->post['theme_default_image_thumb_width'])) { + $data['theme_default_image_thumb_width'] = $this->request->post['theme_default_image_thumb_width']; + } elseif (isset($setting_info['theme_default_image_thumb_width'])) { + $data['theme_default_image_thumb_width'] = $setting_info['theme_default_image_thumb_width']; + } else { + $data['theme_default_image_thumb_width'] = 228; + } + + if (isset($this->request->post['theme_default_image_thumb_height'])) { + $data['theme_default_image_thumb_height'] = $this->request->post['theme_default_image_thumb_height']; + } elseif (isset($setting_info['theme_default_image_thumb_height'])) { + $data['theme_default_image_thumb_height'] = $setting_info['theme_default_image_thumb_height']; + } else { + $data['theme_default_image_thumb_height'] = 228; + } + + if (isset($this->request->post['theme_default_image_popup_width'])) { + $data['theme_default_image_popup_width'] = $this->request->post['theme_default_image_popup_width']; + } elseif (isset($setting_info['theme_default_image_popup_width'])) { + $data['theme_default_image_popup_width'] = $setting_info['theme_default_image_popup_width']; + } else { + $data['theme_default_image_popup_width'] = 500; + } + + if (isset($this->request->post['theme_default_image_popup_height'])) { + $data['theme_default_image_popup_height'] = $this->request->post['theme_default_image_popup_height']; + } elseif (isset($setting_info['theme_default_image_popup_height'])) { + $data['theme_default_image_popup_height'] = $setting_info['theme_default_image_popup_height']; + } else { + $data['theme_default_image_popup_height'] = 500; + } + + if (isset($this->request->post['theme_default_image_product_width'])) { + $data['theme_default_image_product_width'] = $this->request->post['theme_default_image_product_width']; + } elseif (isset($setting_info['theme_default_image_product_width'])) { + $data['theme_default_image_product_width'] = $setting_info['theme_default_image_product_width']; + } else { + $data['theme_default_image_product_width'] = 228; + } + + if (isset($this->request->post['theme_default_image_product_height'])) { + $data['theme_default_image_product_height'] = $this->request->post['theme_default_image_product_height']; + } elseif (isset($setting_info['theme_default_image_product_height'])) { + $data['theme_default_image_product_height'] = $setting_info['theme_default_image_product_height']; + } else { + $data['theme_default_image_product_height'] = 228; + } + + if (isset($this->request->post['theme_default_image_additional_width'])) { + $data['theme_default_image_additional_width'] = $this->request->post['theme_default_image_additional_width']; + } elseif (isset($setting_info['theme_default_image_additional_width'])) { + $data['theme_default_image_additional_width'] = $setting_info['theme_default_image_additional_width']; + } else { + $data['theme_default_image_additional_width'] = 74; + } + + if (isset($this->request->post['theme_default_image_additional_height'])) { + $data['theme_default_image_additional_height'] = $this->request->post['theme_default_image_additional_height']; + } elseif (isset($setting_info['theme_default_image_additional_height'])) { + $data['theme_default_image_additional_height'] = $setting_info['theme_default_image_additional_height']; + } else { + $data['theme_default_image_additional_height'] = 74; + } + + if (isset($this->request->post['theme_default_image_related_width'])) { + $data['theme_default_image_related_width'] = $this->request->post['theme_default_image_related_width']; + } elseif (isset($setting_info['theme_default_image_related_width'])) { + $data['theme_default_image_related_width'] = $setting_info['theme_default_image_related_width']; + } else { + $data['theme_default_image_related_width'] = 80; + } + + if (isset($this->request->post['theme_default_image_related_height'])) { + $data['theme_default_image_related_height'] = $this->request->post['theme_default_image_related_height']; + } elseif (isset($setting_info['theme_default_image_related_height'])) { + $data['theme_default_image_related_height'] = $setting_info['theme_default_image_related_height']; + } else { + $data['theme_default_image_related_height'] = 80; + } + + if (isset($this->request->post['theme_default_image_compare_width'])) { + $data['theme_default_image_compare_width'] = $this->request->post['theme_default_image_compare_width']; + } elseif (isset($setting_info['theme_default_image_compare_width'])) { + $data['theme_default_image_compare_width'] = $setting_info['theme_default_image_compare_width']; + } else { + $data['theme_default_image_compare_width'] = 90; + } + + if (isset($this->request->post['theme_default_image_compare_height'])) { + $data['theme_default_image_compare_height'] = $this->request->post['theme_default_image_compare_height']; + } elseif (isset($setting_info['theme_default_image_compare_height'])) { + $data['theme_default_image_compare_height'] = $setting_info['theme_default_image_compare_height']; + } else { + $data['theme_default_image_compare_height'] = 90; + } + + if (isset($this->request->post['theme_default_image_wishlist_width'])) { + $data['theme_default_image_wishlist_width'] = $this->request->post['theme_default_image_wishlist_width']; + } elseif (isset($setting_info['theme_default_image_wishlist_width'])) { + $data['theme_default_image_wishlist_width'] = $setting_info['theme_default_image_wishlist_width']; + } else { + $data['theme_default_image_wishlist_width'] = 47; + } + + if (isset($this->request->post['theme_default_image_wishlist_height'])) { + $data['theme_default_image_wishlist_height'] = $this->request->post['theme_default_image_wishlist_height']; + } elseif (isset($setting_info['theme_default_image_wishlist_height'])) { + $data['theme_default_image_wishlist_height'] = $setting_info['theme_default_image_wishlist_height']; + } else { + $data['theme_default_image_wishlist_height'] = 47; + } + + if (isset($this->request->post['theme_default_image_cart_width'])) { + $data['theme_default_image_cart_width'] = $this->request->post['theme_default_image_cart_width']; + } elseif (isset($setting_info['theme_default_image_cart_width'])) { + $data['theme_default_image_cart_width'] = $setting_info['theme_default_image_cart_width']; + } else { + $data['theme_default_image_cart_width'] = 47; + } + + if (isset($this->request->post['theme_default_image_cart_height'])) { + $data['theme_default_image_cart_height'] = $this->request->post['theme_default_image_cart_height']; + } elseif (isset($setting_info['theme_default_image_cart_height'])) { + $data['theme_default_image_cart_height'] = $setting_info['theme_default_image_cart_height']; + } else { + $data['theme_default_image_cart_height'] = 47; + } + + if (isset($this->request->post['theme_default_image_location_width'])) { + $data['theme_default_image_location_width'] = $this->request->post['theme_default_image_location_width']; + } elseif (isset($setting_info['theme_default_image_location_width'])) { + $data['theme_default_image_location_width'] = $setting_info['theme_default_image_location_width']; + } else { + $data['theme_default_image_location_width'] = 268; + } + + if (isset($this->request->post['theme_default_image_location_height'])) { + $data['theme_default_image_location_height'] = $this->request->post['theme_default_image_location_height']; + } elseif (isset($setting_info['theme_default_image_location_height'])) { + $data['theme_default_image_location_height'] = $setting_info['theme_default_image_location_height']; + } else { + $data['theme_default_image_location_height'] = 50; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/theme/default', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/theme/default')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['theme_default_product_limit']) { + $this->error['product_limit'] = $this->language->get('error_limit'); + } + + if (!$this->request->post['theme_default_product_description_length']) { + $this->error['product_description_length'] = $this->language->get('error_limit'); + } + + if (!$this->request->post['theme_default_image_category_width'] || !$this->request->post['theme_default_image_category_height']) { + $this->error['image_category'] = $this->language->get('error_image_category'); + } + + if (!$this->request->post['theme_default_image_thumb_width'] || !$this->request->post['theme_default_image_thumb_height']) { + $this->error['image_thumb'] = $this->language->get('error_image_thumb'); + } + + if (!$this->request->post['theme_default_image_popup_width'] || !$this->request->post['theme_default_image_popup_height']) { + $this->error['image_popup'] = $this->language->get('error_image_popup'); + } + + if (!$this->request->post['theme_default_image_product_width'] || !$this->request->post['theme_default_image_product_height']) { + $this->error['image_product'] = $this->language->get('error_image_product'); + } + + if (!$this->request->post['theme_default_image_additional_width'] || !$this->request->post['theme_default_image_additional_height']) { + $this->error['image_additional'] = $this->language->get('error_image_additional'); + } + + if (!$this->request->post['theme_default_image_related_width'] || !$this->request->post['theme_default_image_related_height']) { + $this->error['image_related'] = $this->language->get('error_image_related'); + } + + if (!$this->request->post['theme_default_image_compare_width'] || !$this->request->post['theme_default_image_compare_height']) { + $this->error['image_compare'] = $this->language->get('error_image_compare'); + } + + if (!$this->request->post['theme_default_image_wishlist_width'] || !$this->request->post['theme_default_image_wishlist_height']) { + $this->error['image_wishlist'] = $this->language->get('error_image_wishlist'); + } + + if (!$this->request->post['theme_default_image_cart_width'] || !$this->request->post['theme_default_image_cart_height']) { + $this->error['image_cart'] = $this->language->get('error_image_cart'); + } + + if (!$this->request->post['theme_default_image_location_width'] || !$this->request->post['theme_default_image_location_height']) { + $this->error['image_location'] = $this->language->get('error_image_location'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/total/coupon.php b/public/admin/controller/extension/total/coupon.php new file mode 100644 index 0000000..397e6cc --- /dev/null +++ b/public/admin/controller/extension/total/coupon.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalCoupon extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_coupon', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/coupon', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/coupon', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_coupon_status'])) { + $data['total_coupon_status'] = $this->request->post['total_coupon_status']; + } else { + $data['total_coupon_status'] = $this->config->get('total_coupon_status'); + } + + if (isset($this->request->post['total_coupon_sort_order'])) { + $data['total_coupon_sort_order'] = $this->request->post['total_coupon_sort_order']; + } else { + $data['total_coupon_sort_order'] = $this->config->get('total_coupon_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/coupon', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/credit.php b/public/admin/controller/extension/total/credit.php new file mode 100644 index 0000000..930d3cd --- /dev/null +++ b/public/admin/controller/extension/total/credit.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalCredit extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/credit'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_credit', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/credit', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/credit', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_credit_status'])) { + $data['total_credit_status'] = $this->request->post['total_credit_status']; + } else { + $data['total_credit_status'] = $this->config->get('total_credit_status'); + } + + if (isset($this->request->post['total_credit_sort_order'])) { + $data['total_credit_sort_order'] = $this->request->post['total_credit_sort_order']; + } else { + $data['total_credit_sort_order'] = $this->config->get('total_credit_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/credit', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/credit')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/handling.php b/public/admin/controller/extension/total/handling.php new file mode 100644 index 0000000..123906c --- /dev/null +++ b/public/admin/controller/extension/total/handling.php @@ -0,0 +1,95 @@ +<?php +class ControllerExtensionTotalHandling extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/handling'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_handling', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/handling', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/handling', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_handling_total'])) { + $data['total_handling_total'] = $this->request->post['total_handling_total']; + } else { + $data['total_handling_total'] = $this->config->get('total_handling_total'); + } + + if (isset($this->request->post['total_handling_fee'])) { + $data['total_handling_fee'] = $this->request->post['total_handling_fee']; + } else { + $data['total_handling_fee'] = $this->config->get('total_handling_fee'); + } + + if (isset($this->request->post['total_handling_tax_class_id'])) { + $data['total_handling_tax_class_id'] = $this->request->post['total_handling_tax_class_id']; + } else { + $data['total_handling_tax_class_id'] = $this->config->get('total_handling_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['total_handling_status'])) { + $data['total_handling_status'] = $this->request->post['total_handling_status']; + } else { + $data['total_handling_status'] = $this->config->get('total_handling_status'); + } + + if (isset($this->request->post['total_handling_sort_order'])) { + $data['total_handling_sort_order'] = $this->request->post['total_handling_sort_order']; + } else { + $data['total_handling_sort_order'] = $this->config->get('total_handling_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/handling', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/handling')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/klarna_fee.php b/public/admin/controller/extension/total/klarna_fee.php new file mode 100644 index 0000000..95e9851 --- /dev/null +++ b/public/admin/controller/extension/total/klarna_fee.php @@ -0,0 +1,113 @@ +<?php +class ControllerExtensionTotalKlarnaFee extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/klarna_fee'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['klarna_fee'] as $klarna_account) { + if ($klarna_account['status']) { + $status = true; + + break; + } + } + + $this->model_setting_setting->editSetting('total_klarna_fee', array_merge($this->request->post, array('klarna_fee_status' => $status))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/klarna_fee', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/klarna_fee', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['total_klarna_fee'])) { + $data['total_klarna_fee'] = $this->request->post['total_klarna_fee']; + } else { + $data['total_klarna_fee'] = $this->config->get('total_klarna_fee'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/klarna_fee', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/klarna_fee')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/low_order_fee.php b/public/admin/controller/extension/total/low_order_fee.php new file mode 100644 index 0000000..5defd89 --- /dev/null +++ b/public/admin/controller/extension/total/low_order_fee.php @@ -0,0 +1,95 @@ +<?php +class ControllerExtensionTotalLowOrderFee extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/low_order_fee'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_low_order_fee', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/low_order_fee', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/low_order_fee', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_low_order_fee_total'])) { + $data['total_low_order_fee_total'] = $this->request->post['total_low_order_fee_total']; + } else { + $data['total_low_order_fee_total'] = $this->config->get('total_low_order_fee_total'); + } + + if (isset($this->request->post['total_low_order_fee_fee'])) { + $data['total_low_order_fee_fee'] = $this->request->post['total_low_order_fee_fee']; + } else { + $data['total_low_order_fee_fee'] = $this->config->get('total_low_order_fee_fee'); + } + + if (isset($this->request->post['total_low_order_fee_tax_class_id'])) { + $data['total_low_order_fee_tax_class_id'] = $this->request->post['total_low_order_fee_tax_class_id']; + } else { + $data['total_low_order_fee_tax_class_id'] = $this->config->get('total_low_order_fee_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['total_low_order_fee_status'])) { + $data['total_low_order_fee_status'] = $this->request->post['total_low_order_fee_status']; + } else { + $data['total_low_order_fee_status'] = $this->config->get('total_low_order_fee_status'); + } + + if (isset($this->request->post['total_low_order_fee_sort_order'])) { + $data['total_low_order_fee_sort_order'] = $this->request->post['total_low_order_fee_sort_order']; + } else { + $data['total_low_order_fee_sort_order'] = $this->config->get('total_low_order_fee_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/low_order_fee', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/low_order_fee')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/reward.php b/public/admin/controller/extension/total/reward.php new file mode 100644 index 0000000..eac07db --- /dev/null +++ b/public/admin/controller/extension/total/reward.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalReward extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/reward'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_reward', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/reward', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/reward', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_reward_status'])) { + $data['total_reward_status'] = $this->request->post['total_reward_status']; + } else { + $data['total_reward_status'] = $this->config->get('total_reward_status'); + } + + if (isset($this->request->post['total_reward_sort_order'])) { + $data['total_reward_sort_order'] = $this->request->post['total_reward_sort_order']; + } else { + $data['total_reward_sort_order'] = $this->config->get('total_reward_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/reward', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/reward')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/shipping.php b/public/admin/controller/extension/total/shipping.php new file mode 100644 index 0000000..ef7251d --- /dev/null +++ b/public/admin/controller/extension/total/shipping.php @@ -0,0 +1,79 @@ +<?php +class ControllerExtensionTotalShipping extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/shipping'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_shipping', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/shipping', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/shipping', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_shipping_estimator'])) { + $data['total_shipping_estimator'] = $this->request->post['total_shipping_estimator']; + } else { + $data['total_shipping_estimator'] = $this->config->get('total_shipping_estimator'); + } + + if (isset($this->request->post['total_shipping_status'])) { + $data['total_shipping_status'] = $this->request->post['total_shipping_status']; + } else { + $data['total_shipping_status'] = $this->config->get('total_shipping_status'); + } + + if (isset($this->request->post['total_shipping_sort_order'])) { + $data['total_shipping_sort_order'] = $this->request->post['total_shipping_sort_order']; + } else { + $data['total_shipping_sort_order'] = $this->config->get('total_shipping_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/shipping', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/sub_total.php b/public/admin/controller/extension/total/sub_total.php new file mode 100644 index 0000000..0bff1f8 --- /dev/null +++ b/public/admin/controller/extension/total/sub_total.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalSubTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/sub_total'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_sub_total', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/sub_total', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/sub_total', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_sub_total_status'])) { + $data['total_sub_total_status'] = $this->request->post['total_sub_total_status']; + } else { + $data['total_sub_total_status'] = $this->config->get('total_sub_total_status'); + } + + if (isset($this->request->post['sub_total_sort_order'])) { + $data['sub_total_sort_order'] = $this->request->post['sub_total_sort_order']; + } else { + $data['sub_total_sort_order'] = $this->config->get('sub_total_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/sub_total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/sub_total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/tax.php b/public/admin/controller/extension/total/tax.php new file mode 100644 index 0000000..89d3060 --- /dev/null +++ b/public/admin/controller/extension/total/tax.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalTax extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/tax'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_tax', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/tax', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/tax', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_tax_status'])) { + $data['total_tax_status'] = $this->request->post['total_tax_status']; + } else { + $data['total_tax_status'] = $this->config->get('total_tax_status'); + } + + if (isset($this->request->post['total_tax_sort_order'])) { + $data['total_tax_sort_order'] = $this->request->post['total_tax_sort_order']; + } else { + $data['total_tax_sort_order'] = $this->config->get('total_tax_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/tax', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/tax')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/total.php b/public/admin/controller/extension/total/total.php new file mode 100644 index 0000000..3a24787 --- /dev/null +++ b/public/admin/controller/extension/total/total.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/total'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_total', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/total', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/total', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_total_status'])) { + $data['total_total_status'] = $this->request->post['total_total_status']; + } else { + $data['total_total_status'] = $this->config->get('total_total_status'); + } + + if (isset($this->request->post['total_total_sort_order'])) { + $data['total_total_sort_order'] = $this->request->post['total_total_sort_order']; + } else { + $data['total_total_sort_order'] = $this->config->get('total_total_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/voucher.php b/public/admin/controller/extension/total/voucher.php new file mode 100644 index 0000000..0d7820b --- /dev/null +++ b/public/admin/controller/extension/total/voucher.php @@ -0,0 +1,87 @@ +<?php +class ControllerExtensionTotalVoucher extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_voucher', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/voucher', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/voucher', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_voucher_status'])) { + $data['total_voucher_status'] = $this->request->post['total_voucher_status']; + } else { + $data['total_voucher_status'] = $this->config->get('total_voucher_status'); + } + + if (isset($this->request->post['total_voucher_sort_order'])) { + $data['total_voucher_sort_order'] = $this->request->post['total_voucher_sort_order']; + } else { + $data['total_voucher_sort_order'] = $this->config->get('total_voucher_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/voucher', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + // Register the event triggers + $this->load->model('setting/event'); + + $this->model_setting_event->addEvent('voucher', 'catalog/model/checkout/order/addOrderHistory/after', 'extension/total/voucher/send'); + } + + public function uninstall() { + // delete the event triggers + $this->load->model('setting/event'); + + $this->model_setting_event->deleteEventByCode('voucher'); + } +} diff --git a/public/admin/controller/localisation/country.php b/public/admin/controller/localisation/country.php new file mode 100644 index 0000000..dadc056 --- /dev/null +++ b/public/admin/controller/localisation/country.php @@ -0,0 +1,438 @@ +<?php +class ControllerLocalisationCountry extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_country->addCountry($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_country->editCountry($this->request->get['country_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $country_id) { + $this->model_localisation_country->deleteCountry($country_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/country/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/country/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['countries'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $country_total = $this->model_localisation_country->getTotalCountries(); + + $results = $this->model_localisation_country->getCountries($filter_data); + + foreach ($results as $result) { + $data['countries'][] = array( + 'country_id' => $result['country_id'], + 'name' => $result['name'] . (($result['country_id'] == $this->config->get('config_country_id')) ? $this->language->get('text_default') : null), + 'iso_code_2' => $result['iso_code_2'], + 'iso_code_3' => $result['iso_code_3'], + 'edit' => $this->url->link('localisation/country/edit', 'user_token=' . $this->session->data['user_token'] . '&country_id=' . $result['country_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_iso_code_2'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_2' . $url, true); + $data['sort_iso_code_3'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_3' . $url, true); + + $url = ''; + + 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 = $country_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($country_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($country_total - $this->config->get('config_limit_admin'))) ? $country_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $country_total, ceil($country_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/country_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['country_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['country_id'])) { + $data['action'] = $this->url->link('localisation/country/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/country/edit', 'user_token=' . $this->session->data['user_token'] . '&country_id=' . $this->request->get['country_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['country_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($country_info)) { + $data['name'] = $country_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['iso_code_2'])) { + $data['iso_code_2'] = $this->request->post['iso_code_2']; + } elseif (!empty($country_info)) { + $data['iso_code_2'] = $country_info['iso_code_2']; + } else { + $data['iso_code_2'] = ''; + } + + if (isset($this->request->post['iso_code_3'])) { + $data['iso_code_3'] = $this->request->post['iso_code_3']; + } elseif (!empty($country_info)) { + $data['iso_code_3'] = $country_info['iso_code_3']; + } else { + $data['iso_code_3'] = ''; + } + + if (isset($this->request->post['address_format'])) { + $data['address_format'] = $this->request->post['address_format']; + } elseif (!empty($country_info)) { + $data['address_format'] = $country_info['address_format']; + } else { + $data['address_format'] = ''; + } + + if (isset($this->request->post['postcode_required'])) { + $data['postcode_required'] = $this->request->post['postcode_required']; + } elseif (!empty($country_info)) { + $data['postcode_required'] = $country_info['postcode_required']; + } else { + $data['postcode_required'] = 0; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($country_info)) { + $data['status'] = $country_info['status']; + } else { + $data['status'] = '1'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/country_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/country')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 128)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/country')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('customer/customer'); + $this->load->model('localisation/zone'); + $this->load->model('localisation/geo_zone'); + + foreach ($this->request->post['selected'] as $country_id) { + if ($this->config->get('config_country_id') == $country_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByCountryId($country_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $address_total = $this->model_customer_customer->getTotalAddressesByCountryId($country_id); + + if ($address_total) { + $this->error['warning'] = sprintf($this->language->get('error_address'), $address_total); + } + + $zone_total = $this->model_localisation_zone->getTotalZonesByCountryId($country_id); + + if ($zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone'), $zone_total); + } + + $zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByCountryId($country_id); + + if ($zone_to_geo_zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total); + } + } + + 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->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/currency.php b/public/admin/controller/localisation/currency.php new file mode 100644 index 0000000..68a0c97 --- /dev/null +++ b/public/admin/controller/localisation/currency.php @@ -0,0 +1,463 @@ +<?php +class ControllerLocalisationCurrency extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_currency->addCurrency($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_currency->editCurrency($this->request->get['currency_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $currency_id) { + $this->model_localisation_currency->deleteCurrency($currency_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function refresh() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if ($this->validateRefresh()) { + $this->model_localisation_currency->refresh(true); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/currency/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/currency/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['refresh'] = $this->url->link('localisation/currency/refresh', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['currencies'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $currency_total = $this->model_localisation_currency->getTotalCurrencies(); + + $results = $this->model_localisation_currency->getCurrencies($filter_data); + + foreach ($results as $result) { + $data['currencies'][] = array( + 'currency_id' => $result['currency_id'], + 'title' => $result['title'] . (($result['code'] == $this->config->get('config_currency')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'value' => $result['value'], + 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])), + 'edit' => $this->url->link('localisation/currency/edit', 'user_token=' . $this->session->data['user_token'] . '¤cy_id=' . $result['currency_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_code'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_value'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + $data['sort_date_modified'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url, true); + + $url = ''; + + 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 = $currency_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($currency_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($currency_total - $this->config->get('config_limit_admin'))) ? $currency_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $currency_total, ceil($currency_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/currency_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['currency_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['currency_id'])) { + $data['action'] = $this->url->link('localisation/currency/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/currency/edit', 'user_token=' . $this->session->data['user_token'] . '¤cy_id=' . $this->request->get['currency_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['currency_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $currency_info = $this->model_localisation_currency->getCurrency($this->request->get['currency_id']); + } + + if (isset($this->request->post['title'])) { + $data['title'] = $this->request->post['title']; + } elseif (!empty($currency_info)) { + $data['title'] = $currency_info['title']; + } else { + $data['title'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($currency_info)) { + $data['code'] = $currency_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['symbol_left'])) { + $data['symbol_left'] = $this->request->post['symbol_left']; + } elseif (!empty($currency_info)) { + $data['symbol_left'] = $currency_info['symbol_left']; + } else { + $data['symbol_left'] = ''; + } + + if (isset($this->request->post['symbol_right'])) { + $data['symbol_right'] = $this->request->post['symbol_right']; + } elseif (!empty($currency_info)) { + $data['symbol_right'] = $currency_info['symbol_right']; + } else { + $data['symbol_right'] = ''; + } + + if (isset($this->request->post['decimal_place'])) { + $data['decimal_place'] = $this->request->post['decimal_place']; + } elseif (!empty($currency_info)) { + $data['decimal_place'] = $currency_info['decimal_place']; + } else { + $data['decimal_place'] = ''; + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($currency_info)) { + $data['value'] = $currency_info['value']; + } else { + $data['value'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($currency_info)) { + $data['status'] = $currency_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/currency_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['title']) < 3) || (utf8_strlen($this->request->post['title']) > 32)) { + $this->error['title'] = $this->language->get('error_title'); + } + + if (utf8_strlen($this->request->post['code']) != 3) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $currency_id) { + $currency_info = $this->model_localisation_currency->getCurrency($currency_id); + + if ($currency_info) { + if ($this->config->get('config_currency') == $currency_info['code']) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByCurrency($currency_info['code']); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + $order_total = $this->model_sale_order->getTotalOrdersByCurrencyId($currency_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } + + protected function validateRefresh() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/geo_zone.php b/public/admin/controller/localisation/geo_zone.php new file mode 100644 index 0000000..5174e4d --- /dev/null +++ b/public/admin/controller/localisation/geo_zone.php @@ -0,0 +1,377 @@ +<?php +class ControllerLocalisationGeoZone extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_geo_zone->addGeoZone($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_geo_zone->editGeoZone($this->request->get['geo_zone_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $geo_zone_id) { + $this->model_localisation_geo_zone->deleteGeoZone($geo_zone_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/geo_zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/geo_zone/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['geo_zones'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $geo_zone_total = $this->model_localisation_geo_zone->getTotalGeoZones(); + + $results = $this->model_localisation_geo_zone->getGeoZones($filter_data); + + foreach ($results as $result) { + $data['geo_zones'][] = array( + 'geo_zone_id' => $result['geo_zone_id'], + 'name' => $result['name'], + 'description' => $result['description'], + 'edit' => $this->url->link('localisation/geo_zone/edit', 'user_token=' . $this->session->data['user_token'] . '&geo_zone_id=' . $result['geo_zone_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_description'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . '&sort=description' . $url, true); + + $url = ''; + + 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 = $geo_zone_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($geo_zone_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($geo_zone_total - $this->config->get('config_limit_admin'))) ? $geo_zone_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $geo_zone_total, ceil($geo_zone_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/geo_zone_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['geo_zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['description'])) { + $data['error_description'] = $this->error['description']; + } else { + $data['error_description'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['geo_zone_id'])) { + $data['action'] = $this->url->link('localisation/geo_zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/geo_zone/edit', 'user_token=' . $this->session->data['user_token'] . '&geo_zone_id=' . $this->request->get['geo_zone_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['geo_zone_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $geo_zone_info = $this->model_localisation_geo_zone->getGeoZone($this->request->get['geo_zone_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($geo_zone_info)) { + $data['name'] = $geo_zone_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($geo_zone_info)) { + $data['description'] = $geo_zone_info['description']; + } else { + $data['description'] = ''; + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + if (isset($this->request->post['zone_to_geo_zone'])) { + $data['zone_to_geo_zones'] = $this->request->post['zone_to_geo_zone']; + } elseif (isset($this->request->get['geo_zone_id'])) { + $data['zone_to_geo_zones'] = $this->model_localisation_geo_zone->getZoneToGeoZones($this->request->get['geo_zone_id']); + } else { + $data['zone_to_geo_zones'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/geo_zone_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['description']) < 3) || (utf8_strlen($this->request->post['description']) > 255)) { + $this->error['description'] = $this->language->get('error_description'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/tax_rate'); + + foreach ($this->request->post['selected'] as $geo_zone_id) { + $tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRatesByGeoZoneId($geo_zone_id); + + if ($tax_rate_total) { + $this->error['warning'] = sprintf($this->language->get('error_tax_rate'), $tax_rate_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/language.php b/public/admin/controller/localisation/language.php new file mode 100644 index 0000000..8090282 --- /dev/null +++ b/public/admin/controller/localisation/language.php @@ -0,0 +1,438 @@ +<?php +class ControllerLocalisationLanguage extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_language->addLanguage($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_language->editLanguage($this->request->get['language_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $language_id) { + $this->model_localisation_language->deleteLanguage($language_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/language/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/language/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['languages'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $language_total = $this->model_localisation_language->getTotalLanguages(); + + $results = $this->model_localisation_language->getLanguages($filter_data); + + foreach ($results as $result) { + $data['languages'][] = array( + 'language_id' => $result['language_id'], + 'name' => $result['name'] . (($result['code'] == $this->config->get('config_language')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('localisation/language/edit', 'user_token=' . $this->session->data['user_token'] . '&language_id=' . $result['language_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_code'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_sort_order'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true); + + $url = ''; + + 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 = $language_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($language_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($language_total - $this->config->get('config_limit_admin'))) ? $language_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $language_total, ceil($language_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/language_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['language_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + if (isset($this->error['locale'])) { + $data['error_locale'] = $this->error['locale']; + } else { + $data['error_locale'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['language_id'])) { + $data['action'] = $this->url->link('localisation/language/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/language/edit', 'user_token=' . $this->session->data['user_token'] . '&language_id=' . $this->request->get['language_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['language_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $language_info = $this->model_localisation_language->getLanguage($this->request->get['language_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($language_info)) { + $data['name'] = $language_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($language_info)) { + $data['code'] = $language_info['code']; + } else { + $data['code'] = ''; + } + + $data['languages'] = array(); + + $folders = glob(DIR_LANGUAGE . '*', GLOB_ONLYDIR); + + foreach ($folders as $folder) { + $data['languages'][] = basename($folder); + } + + if (isset($this->request->post['locale'])) { + $data['locale'] = $this->request->post['locale']; + } elseif (!empty($language_info)) { + $data['locale'] = $language_info['locale']; + } else { + $data['locale'] = ''; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($language_info)) { + $data['sort_order'] = $language_info['sort_order']; + } else { + $data['sort_order'] = 1; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($language_info)) { + $data['status'] = $language_info['status']; + } else { + $data['status'] = true; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/language_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/language')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (utf8_strlen($this->request->post['code']) < 2) { + $this->error['code'] = $this->language->get('error_code'); + } + + if (!$this->request->post['locale']) { + $this->error['locale'] = $this->language->get('error_locale'); + } + + $language_info = $this->model_localisation_language->getLanguageByCode($this->request->post['code']); + + if (!isset($this->request->get['language_id'])) { + if ($language_info) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } else { + if ($language_info && ($this->request->get['language_id'] != $language_info['language_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/language')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $language_id) { + $language_info = $this->model_localisation_language->getLanguage($language_id); + + if ($language_info) { + if ($this->config->get('config_language') == $language_info['code']) { + $this->error['warning'] = $this->language->get('error_default'); + } + + if ($this->config->get('config_admin_language') == $language_info['code']) { + $this->error['warning'] = $this->language->get('error_admin'); + } + + $store_total = $this->model_setting_store->getTotalStoresByLanguage($language_info['code']); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + $order_total = $this->model_sale_order->getTotalOrdersByLanguageId($language_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/length_class.php b/public/admin/controller/localisation/length_class.php new file mode 100644 index 0000000..8a5ce59 --- /dev/null +++ b/public/admin/controller/localisation/length_class.php @@ -0,0 +1,375 @@ +<?php +class ControllerLocalisationLengthClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_length_class->addLengthClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_length_class->editLengthClass($this->request->get['length_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $length_class_id) { + $this->model_localisation_length_class->deleteLengthClass($length_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/length_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/length_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['length_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $length_class_total = $this->model_localisation_length_class->getTotalLengthClasses(); + + $results = $this->model_localisation_length_class->getLengthClasses($filter_data); + + foreach ($results as $result) { + $data['length_classes'][] = array( + 'length_class_id' => $result['length_class_id'], + 'title' => $result['title'] . (($result['length_class_id'] == $this->config->get('config_length_class_id')) ? $this->language->get('text_default') : null), + 'unit' => $result['unit'], + 'value' => $result['value'], + 'edit' => $this->url->link('localisation/length_class/edit', 'user_token=' . $this->session->data['user_token'] . '&length_class_id=' . $result['length_class_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_unit'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url, true); + $data['sort_value'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $url = ''; + + 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 = $length_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($length_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($length_class_total - $this->config->get('config_limit_admin'))) ? $length_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $length_class_total, ceil($length_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/length_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['length_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = array(); + } + + if (isset($this->error['unit'])) { + $data['error_unit'] = $this->error['unit']; + } else { + $data['error_unit'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['length_class_id'])) { + $data['action'] = $this->url->link('localisation/length_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/length_class/edit', 'user_token=' . $this->session->data['user_token'] . '&length_class_id=' . $this->request->get['length_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['length_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $length_class_info = $this->model_localisation_length_class->getLengthClass($this->request->get['length_class_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['length_class_description'])) { + $data['length_class_description'] = $this->request->post['length_class_description']; + } elseif (isset($this->request->get['length_class_id'])) { + $data['length_class_description'] = $this->model_localisation_length_class->getLengthClassDescriptions($this->request->get['length_class_id']); + } else { + $data['length_class_description'] = array(); + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($length_class_info)) { + $data['value'] = $length_class_info['value']; + } else { + $data['value'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/length_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/length_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['length_class_description'] as $language_id => $value) { + if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 32)) { + $this->error['title'][$language_id] = $this->language->get('error_title'); + } + + if (!$value['unit'] || (utf8_strlen($value['unit']) > 4)) { + $this->error['unit'][$language_id] = $this->language->get('error_unit'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/length_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $length_class_id) { + if ($this->config->get('config_length_class_id') == $length_class_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $product_total = $this->model_catalog_product->getTotalProductsByLengthClassId($length_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/location.php b/public/admin/controller/localisation/location.php new file mode 100644 index 0000000..d01ba17 --- /dev/null +++ b/public/admin/controller/localisation/location.php @@ -0,0 +1,427 @@ +<?php +class ControllerLocalisationLocation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_location->addLocation($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_location->editLocation($this->request->get['location_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $location_id) { + $this->model_localisation_location->deleteLocation($location_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/location/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/location/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['location'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $location_total = $this->model_localisation_location->getTotalLocations(); + + $results = $this->model_localisation_location->getLocations($filter_data); + + foreach ($results as $result) { + $data['location'][] = array( + 'location_id' => $result['location_id'], + 'name' => $result['name'], + 'address' => $result['address'], + 'edit' => $this->url->link('localisation/location/edit', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $result['location_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_address'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . '&sort=address' . $url, true); + + $url = ''; + + 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 = $location_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($location_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($location_total - $this->config->get('config_limit_admin'))) ? $location_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $location_total, ceil($location_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/location_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['location_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['address'])) { + $data['error_address'] = $this->error['address']; + } else { + $data['error_address'] = ''; + } + + if (isset($this->error['telephone'])) { + $data['error_telephone'] = $this->error['telephone']; + } else { + $data['error_telephone'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['location_id'])) { + $data['action'] = $this->url->link('localisation/location/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/location/edit', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $this->request->get['location_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['location_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $location_info = $this->model_localisation_location->getLocation($this->request->get['location_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('setting/store'); + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($location_info)) { + $data['name'] = $location_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['address'])) { + $data['address'] = $this->request->post['address']; + } elseif (!empty($location_info)) { + $data['address'] = $location_info['address']; + } else { + $data['address'] = ''; + } + + if (isset($this->request->post['geocode'])) { + $data['geocode'] = $this->request->post['geocode']; + } elseif (!empty($location_info)) { + $data['geocode'] = $location_info['geocode']; + } else { + $data['geocode'] = ''; + } + + if (isset($this->request->post['telephone'])) { + $data['telephone'] = $this->request->post['telephone']; + } elseif (!empty($location_info)) { + $data['telephone'] = $location_info['telephone']; + } else { + $data['telephone'] = ''; + } + + if (isset($this->request->post['fax'])) { + $data['fax'] = $this->request->post['fax']; + } elseif (!empty($location_info)) { + $data['fax'] = $location_info['fax']; + } else { + $data['fax'] = ''; + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($location_info)) { + $data['image'] = $location_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($location_info) && is_file(DIR_IMAGE . $location_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($location_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['open'])) { + $data['open'] = $this->request->post['open']; + } elseif (!empty($location_info)) { + $data['open'] = $location_info['open']; + } else { + $data['open'] = ''; + } + + if (isset($this->request->post['comment'])) { + $data['comment'] = $this->request->post['comment']; + } elseif (!empty($location_info)) { + $data['comment'] = $location_info['comment']; + } else { + $data['comment'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/location_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/location')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['address']) < 3) || (utf8_strlen($this->request->post['address']) > 128)) { + $this->error['address'] = $this->language->get('error_address'); + } + + if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/location')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/order_status.php b/public/admin/controller/localisation/order_status.php new file mode 100644 index 0000000..7092113 --- /dev/null +++ b/public/admin/controller/localisation/order_status.php @@ -0,0 +1,366 @@ +<?php +class ControllerLocalisationOrderStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_order_status->addOrderStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_order_status->editOrderStatus($this->request->get['order_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $order_status_id) { + $this->model_localisation_order_status->deleteOrderStatus($order_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/order_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/order_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['order_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_status_total = $this->model_localisation_order_status->getTotalOrderStatuses(); + + $results = $this->model_localisation_order_status->getOrderStatuses($filter_data); + + foreach ($results as $result) { + $data['order_statuses'][] = array( + 'order_status_id' => $result['order_status_id'], + 'name' => $result['name'] . (($result['order_status_id'] == $this->config->get('config_order_status_id')) ? $this->language->get('text_default') : null), + 'edit' => $this->url->link('localisation/order_status/edit', 'user_token=' . $this->session->data['user_token'] . '&order_status_id=' . $result['order_status_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_status_total - $this->config->get('config_limit_admin'))) ? $order_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_status_total, ceil($order_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/order_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['order_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['order_status_id'])) { + $data['action'] = $this->url->link('localisation/order_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/order_status/edit', 'user_token=' . $this->session->data['user_token'] . '&order_status_id=' . $this->request->get['order_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['order_status'])) { + $data['order_status'] = $this->request->post['order_status']; + } elseif (isset($this->request->get['order_status_id'])) { + $data['order_status'] = $this->model_localisation_order_status->getOrderStatusDescriptions($this->request->get['order_status_id']); + } else { + $data['order_status'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/order_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/order_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['order_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/order_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $order_status_id) { + if ($this->config->get('config_order_status_id') == $order_status_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + if ($this->config->get('config_download_status_id') == $order_status_id) { + $this->error['warning'] = $this->language->get('error_download'); + } + + $store_total = $this->model_setting_store->getTotalStoresByOrderStatusId($order_status_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $order_total = $this->model_sale_order->getTotalOrdersByOrderStatusId($order_status_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + + $order_total = $this->model_sale_order->getTotalOrderHistoriesByOrderStatusId($order_status_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/return_action.php b/public/admin/controller/localisation/return_action.php new file mode 100644 index 0000000..6dc5ff9 --- /dev/null +++ b/public/admin/controller/localisation/return_action.php @@ -0,0 +1,345 @@ +<?php +class ControllerLocalisationReturnAction extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_action->addReturnAction($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_action->editReturnAction($this->request->get['return_action_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_action_id) { + $this->model_localisation_return_action->deleteReturnAction($return_action_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_action/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_action/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_actions'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_action_total = $this->model_localisation_return_action->getTotalReturnActions(); + + $results = $this->model_localisation_return_action->getReturnActions($filter_data); + + foreach ($results as $result) { + $data['return_actions'][] = array( + 'return_action_id' => $result['return_action_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/return_action/edit', 'user_token=' . $this->session->data['user_token'] . '&return_action_id=' . $result['return_action_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $return_action_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_action_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_action_total - $this->config->get('config_limit_admin'))) ? $return_action_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_action_total, ceil($return_action_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_action_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_action_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_action_id'])) { + $data['action'] = $this->url->link('localisation/return_action/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_action/edit', 'user_token=' . $this->session->data['user_token'] . '&return_action_id=' . $this->request->get['return_action_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_action'])) { + $data['return_action'] = $this->request->post['return_action']; + } elseif (isset($this->request->get['return_action_id'])) { + $data['return_action'] = $this->model_localisation_return_action->getReturnActionDescriptions($this->request->get['return_action_id']); + } else { + $data['return_action'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_action_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_action')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_action'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 64)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_action')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_action_id) { + $return_total = $this->model_sale_return->getTotalReturnsByReturnActionId($return_action_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/return_reason.php b/public/admin/controller/localisation/return_reason.php new file mode 100644 index 0000000..4be8c54 --- /dev/null +++ b/public/admin/controller/localisation/return_reason.php @@ -0,0 +1,345 @@ +<?php +class ControllerLocalisationReturnReason extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_reason->addReturnReason($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_reason->editReturnReason($this->request->get['return_reason_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_reason_id) { + $this->model_localisation_return_reason->deleteReturnReason($return_reason_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_reason/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_reason/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_reasons'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_reason_total = $this->model_localisation_return_reason->getTotalReturnReasons(); + + $results = $this->model_localisation_return_reason->getReturnReasons($filter_data); + + foreach ($results as $result) { + $data['return_reasons'][] = array( + 'return_reason_id' => $result['return_reason_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/return_reason/edit', 'user_token=' . $this->session->data['user_token'] . '&return_reason_id=' . $result['return_reason_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $return_reason_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_reason_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_reason_total - $this->config->get('config_limit_admin'))) ? $return_reason_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_reason_total, ceil($return_reason_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_reason_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_reason_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_reason_id'])) { + $data['action'] = $this->url->link('localisation/return_reason/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_reason/edit', 'user_token=' . $this->session->data['user_token'] . '&return_reason_id=' . $this->request->get['return_reason_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_reason'])) { + $data['return_reason'] = $this->request->post['return_reason']; + } elseif (isset($this->request->get['return_reason_id'])) { + $data['return_reason'] = $this->model_localisation_return_reason->getReturnReasonDescriptions($this->request->get['return_reason_id']); + } else { + $data['return_reason'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_reason_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_reason')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_reason'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 128)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_reason')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_reason_id) { + $return_total = $this->model_sale_return->getTotalReturnsByReturnReasonId($return_reason_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/return_status.php b/public/admin/controller/localisation/return_status.php new file mode 100644 index 0000000..42d2b4a --- /dev/null +++ b/public/admin/controller/localisation/return_status.php @@ -0,0 +1,355 @@ +<?php +class ControllerLocalisationReturnStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_status->addReturnStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_status->editReturnStatus($this->request->get['return_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_status_id) { + $this->model_localisation_return_status->deleteReturnStatus($return_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_status_total = $this->model_localisation_return_status->getTotalReturnStatuses(); + + $results = $this->model_localisation_return_status->getReturnStatuses($filter_data); + + foreach ($results as $result) { + $data['return_statuses'][] = array( + 'return_status_id' => $result['return_status_id'], + 'name' => $result['name'] . (($result['return_status_id'] == $this->config->get('config_return_status_id')) ? $this->language->get('text_default') : null), + 'edit' => $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $result['return_status_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $return_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_status_total - $this->config->get('config_limit_admin'))) ? $return_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_status_total, ceil($return_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_status_id'])) { + $data['action'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $this->request->get['return_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_status'])) { + $data['return_status'] = $this->request->post['return_status']; + } elseif (isset($this->request->get['return_status_id'])) { + $data['return_status'] = $this->model_localisation_return_status->getReturnStatusDescriptions($this->request->get['return_status_id']); + } else { + $data['return_status'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/return_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_status_id) { + if ($this->config->get('config_return_status_id') == $return_status_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $return_total = $this->model_sale_return->getTotalReturnsByReturnStatusId($return_status_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + + $return_total = $this->model_sale_return->getTotalReturnHistoriesByReturnStatusId($return_status_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/stock_status.php b/public/admin/controller/localisation/stock_status.php new file mode 100644 index 0000000..27e6df4 --- /dev/null +++ b/public/admin/controller/localisation/stock_status.php @@ -0,0 +1,346 @@ +<?php +class ControllerLocalisationStockStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_stock_status->addStockStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_stock_status->editStockStatus($this->request->get['stock_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $stock_status_id) { + $this->model_localisation_stock_status->deleteStockStatus($stock_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/stock_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/stock_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['stock_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $stock_status_total = $this->model_localisation_stock_status->getTotalStockStatuses(); + + $results = $this->model_localisation_stock_status->getStockStatuses($filter_data); + + foreach ($results as $result) { + $data['stock_statuses'][] = array( + 'stock_status_id' => $result['stock_status_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/stock_status/edit', 'user_token=' . $this->session->data['user_token'] . '&stock_status_id=' . $result['stock_status_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $stock_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($stock_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($stock_status_total - $this->config->get('config_limit_admin'))) ? $stock_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $stock_status_total, ceil($stock_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/stock_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['stock_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['stock_status_id'])) { + $data['action'] = $this->url->link('localisation/stock_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/stock_status/edit', 'user_token=' . $this->session->data['user_token'] . '&stock_status_id=' . $this->request->get['stock_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['stock_status'])) { + $data['stock_status'] = $this->request->post['stock_status']; + } elseif (isset($this->request->get['stock_status_id'])) { + $data['stock_status'] = $this->model_localisation_stock_status->getStockStatusDescriptions($this->request->get['stock_status_id']); + } else { + $data['stock_status'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/stock_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/stock_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['stock_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/stock_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $stock_status_id) { + $product_total = $this->model_catalog_product->getTotalProductsByStockStatusId($stock_status_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/tax_class.php b/public/admin/controller/localisation/tax_class.php new file mode 100644 index 0000000..77a239c --- /dev/null +++ b/public/admin/controller/localisation/tax_class.php @@ -0,0 +1,373 @@ +<?php +class ControllerLocalisationTaxClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_class->addTaxClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_class->editTaxClass($this->request->get['tax_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $tax_class_id) { + $this->model_localisation_tax_class->deleteTaxClass($tax_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/tax_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/tax_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['tax_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $tax_class_total = $this->model_localisation_tax_class->getTotalTaxClasses(); + + $results = $this->model_localisation_tax_class->getTaxClasses($filter_data); + + foreach ($results as $result) { + $data['tax_classes'][] = array( + 'tax_class_id' => $result['tax_class_id'], + 'title' => $result['title'], + 'edit' => $this->url->link('localisation/tax_class/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_class_id=' . $result['tax_class_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + + $url = ''; + + 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 = $tax_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($tax_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($tax_class_total - $this->config->get('config_limit_admin'))) ? $tax_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $tax_class_total, ceil($tax_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/tax_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['tax_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = ''; + } + + if (isset($this->error['description'])) { + $data['error_description'] = $this->error['description']; + } else { + $data['error_description'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['tax_class_id'])) { + $data['action'] = $this->url->link('localisation/tax_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/tax_class/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_class_id=' . $this->request->get['tax_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['tax_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $tax_class_info = $this->model_localisation_tax_class->getTaxClass($this->request->get['tax_class_id']); + } + + if (isset($this->request->post['title'])) { + $data['title'] = $this->request->post['title']; + } elseif (!empty($tax_class_info)) { + $data['title'] = $tax_class_info['title']; + } else { + $data['title'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($tax_class_info)) { + $data['description'] = $tax_class_info['description']; + } else { + $data['description'] = ''; + } + + $this->load->model('localisation/tax_rate'); + + $data['tax_rates'] = $this->model_localisation_tax_rate->getTaxRates(); + + if (isset($this->request->post['tax_rule'])) { + $data['tax_rules'] = $this->request->post['tax_rule']; + } elseif (isset($this->request->get['tax_class_id'])) { + $data['tax_rules'] = $this->model_localisation_tax_class->getTaxRules($this->request->get['tax_class_id']); + } else { + $data['tax_rules'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/tax_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/tax_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['title']) < 3) || (utf8_strlen($this->request->post['title']) > 32)) { + $this->error['title'] = $this->language->get('error_title'); + } + + if ((utf8_strlen($this->request->post['description']) < 3) || (utf8_strlen($this->request->post['description']) > 255)) { + $this->error['description'] = $this->language->get('error_description'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/tax_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $tax_class_id) { + $product_total = $this->model_catalog_product->getTotalProductsByTaxClassId($tax_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/tax_rate.php b/public/admin/controller/localisation/tax_rate.php new file mode 100644 index 0000000..5cf8f58 --- /dev/null +++ b/public/admin/controller/localisation/tax_rate.php @@ -0,0 +1,403 @@ +<?php +class ControllerLocalisationTaxRate extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_rate->addTaxRate($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_rate->editTaxRate($this->request->get['tax_rate_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $tax_rate_id) { + $this->model_localisation_tax_rate->deleteTaxRate($tax_rate_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'tr.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/tax_rate/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/tax_rate/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['tax_rates'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRates(); + + $results = $this->model_localisation_tax_rate->getTaxRates($filter_data); + + foreach ($results as $result) { + $data['tax_rates'][] = array( + 'tax_rate_id' => $result['tax_rate_id'], + 'name' => $result['name'], + 'rate' => $result['rate'], + 'type' => ($result['type'] == 'F' ? $this->language->get('text_amount') : $this->language->get('text_percent')), + 'geo_zone' => $result['geo_zone'], + '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'])), + 'edit' => $this->url->link('localisation/tax_rate/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_rate_id=' . $result['tax_rate_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.name' . $url, true); + $data['sort_rate'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.rate' . $url, true); + $data['sort_type'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.type' . $url, true); + $data['sort_geo_zone'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=gz.name' . $url, true); + $data['sort_date_added'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_modified' . $url, true); + + $url = ''; + + 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 = $tax_rate_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($tax_rate_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($tax_rate_total - $this->config->get('config_limit_admin'))) ? $tax_rate_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $tax_rate_total, ceil($tax_rate_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/tax_rate_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['tax_rate_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['rate'])) { + $data['error_rate'] = $this->error['rate']; + } else { + $data['error_rate'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['tax_rate_id'])) { + $data['action'] = $this->url->link('localisation/tax_rate/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/tax_rate/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_rate_id=' . $this->request->get['tax_rate_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['tax_rate_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $tax_rate_info = $this->model_localisation_tax_rate->getTaxRate($this->request->get['tax_rate_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($tax_rate_info)) { + $data['name'] = $tax_rate_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['rate'])) { + $data['rate'] = $this->request->post['rate']; + } elseif (!empty($tax_rate_info)) { + $data['rate'] = $tax_rate_info['rate']; + } else { + $data['rate'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } elseif (!empty($tax_rate_info)) { + $data['type'] = $tax_rate_info['type']; + } else { + $data['type'] = ''; + } + + if (isset($this->request->post['tax_rate_customer_group'])) { + $data['tax_rate_customer_group'] = $this->request->post['tax_rate_customer_group']; + } elseif (isset($this->request->get['tax_rate_id'])) { + $data['tax_rate_customer_group'] = $this->model_localisation_tax_rate->getTaxRateCustomerGroups($this->request->get['tax_rate_id']); + } else { + $data['tax_rate_customer_group'] = array($this->config->get('config_customer_group_id')); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['geo_zone_id'])) { + $data['geo_zone_id'] = $this->request->post['geo_zone_id']; + } elseif (!empty($tax_rate_info)) { + $data['geo_zone_id'] = $tax_rate_info['geo_zone_id']; + } else { + $data['geo_zone_id'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/tax_rate_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['rate']) { + $this->error['rate'] = $this->language->get('error_rate'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/tax_class'); + + foreach ($this->request->post['selected'] as $tax_rate_id) { + $tax_rule_total = $this->model_localisation_tax_class->getTotalTaxRulesByTaxRateId($tax_rate_id); + + if ($tax_rule_total) { + $this->error['warning'] = sprintf($this->language->get('error_tax_rule'), $tax_rule_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/weight_class.php b/public/admin/controller/localisation/weight_class.php new file mode 100644 index 0000000..6ef50e0 --- /dev/null +++ b/public/admin/controller/localisation/weight_class.php @@ -0,0 +1,375 @@ +<?php +class ControllerLocalisationWeightClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_weight_class->addWeightClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_weight_class->editWeightClass($this->request->get['weight_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $weight_class_id) { + $this->model_localisation_weight_class->deleteWeightClass($weight_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/weight_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/weight_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['weight_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $weight_class_total = $this->model_localisation_weight_class->getTotalWeightClasses(); + + $results = $this->model_localisation_weight_class->getWeightClasses($filter_data); + + foreach ($results as $result) { + $data['weight_classes'][] = array( + 'weight_class_id' => $result['weight_class_id'], + 'title' => $result['title'] . (($result['weight_class_id'] == $this->config->get('config_weight_class_id')) ? $this->language->get('text_default') : null), + 'unit' => $result['unit'], + 'value' => $result['value'], + 'edit' => $this->url->link('localisation/weight_class/edit', 'user_token=' . $this->session->data['user_token'] . '&weight_class_id=' . $result['weight_class_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_unit'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url, true); + $data['sort_value'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $url = ''; + + 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 = $weight_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($weight_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($weight_class_total - $this->config->get('config_limit_admin'))) ? $weight_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $weight_class_total, ceil($weight_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/weight_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['weight_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = array(); + } + + if (isset($this->error['unit'])) { + $data['error_unit'] = $this->error['unit']; + } else { + $data['error_unit'] = array(); + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['weight_class_id'])) { + $data['action'] = $this->url->link('localisation/weight_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/weight_class/edit', 'user_token=' . $this->session->data['user_token'] . '&weight_class_id=' . $this->request->get['weight_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['weight_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $weight_class_info = $this->model_localisation_weight_class->getWeightClass($this->request->get['weight_class_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['weight_class_description'])) { + $data['weight_class_description'] = $this->request->post['weight_class_description']; + } elseif (isset($this->request->get['weight_class_id'])) { + $data['weight_class_description'] = $this->model_localisation_weight_class->getWeightClassDescriptions($this->request->get['weight_class_id']); + } else { + $data['weight_class_description'] = array(); + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($weight_class_info)) { + $data['value'] = $weight_class_info['value']; + } else { + $data['value'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/weight_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/weight_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['weight_class_description'] as $language_id => $value) { + if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 32)) { + $this->error['title'][$language_id] = $this->language->get('error_title'); + } + + if (!$value['unit'] || (utf8_strlen($value['unit']) > 4)) { + $this->error['unit'][$language_id] = $this->language->get('error_unit'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/weight_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $weight_class_id) { + if ($this->config->get('config_weight_class_id') == $weight_class_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $product_total = $this->model_catalog_product->getTotalProductsByWeightClassId($weight_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/zone.php b/public/admin/controller/localisation/zone.php new file mode 100644 index 0000000..df3c262 --- /dev/null +++ b/public/admin/controller/localisation/zone.php @@ -0,0 +1,393 @@ +<?php +class ControllerLocalisationZone extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_zone->addZone($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_zone->editZone($this->request->get['zone_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $zone_id) { + $this->model_localisation_zone->deleteZone($zone_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'c.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/zone/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['zones'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $zone_total = $this->model_localisation_zone->getTotalZones(); + + $results = $this->model_localisation_zone->getZones($filter_data); + + foreach ($results as $result) { + $data['zones'][] = array( + 'zone_id' => $result['zone_id'], + 'country' => $result['country'], + 'name' => $result['name'] . (($result['zone_id'] == $this->config->get('config_zone_id')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'edit' => $this->url->link('localisation/zone/edit', 'user_token=' . $this->session->data['user_token'] . '&zone_id=' . $result['zone_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_country'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=c.name' . $url, true); + $data['sort_name'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.name' . $url, true); + $data['sort_code'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.code' . $url, true); + + $url = ''; + + 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 = $zone_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($zone_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($zone_total - $this->config->get('config_limit_admin'))) ? $zone_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $zone_total, ceil($zone_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/zone_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['zone_id'])) { + $data['action'] = $this->url->link('localisation/zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/zone/edit', 'user_token=' . $this->session->data['user_token'] . '&zone_id=' . $this->request->get['zone_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['zone_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $zone_info = $this->model_localisation_zone->getZone($this->request->get['zone_id']); + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($zone_info)) { + $data['status'] = $zone_info['status']; + } else { + $data['status'] = '1'; + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($zone_info)) { + $data['name'] = $zone_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($zone_info)) { + $data['code'] = $zone_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['country_id'])) { + $data['country_id'] = $this->request->post['country_id']; + } elseif (!empty($zone_info)) { + $data['country_id'] = $zone_info['country_id']; + } else { + $data['country_id'] = ''; + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('localisation/zone_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('customer/customer'); + $this->load->model('localisation/geo_zone'); + + foreach ($this->request->post['selected'] as $zone_id) { + if ($this->config->get('config_zone_id') == $zone_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByZoneId($zone_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $address_total = $this->model_customer_customer->getTotalAddressesByZoneId($zone_id); + + if ($address_total) { + $this->error['warning'] = sprintf($this->language->get('error_address'), $address_total); + } + + $zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByZoneId($zone_id); + + if ($zone_to_geo_zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/mail/affiliate.php b/public/admin/controller/mail/affiliate.php new file mode 100644 index 0000000..3a01a51 --- /dev/null +++ b/public/admin/controller/mail/affiliate.php @@ -0,0 +1,114 @@ +<?php +class ControllerMailAffiliate extends Controller { + public function approve(&$route, &$args, &$output) { + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($args[0]); + + if ($customer_info) { + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8'); + $store_url = $store_info['url'] . 'index.php?route=account/login'; + } else { + $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); + $store_url = HTTP_CATALOG . 'index.php?route=account/login'; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']); + + if ($language_info) { + $language_code = $language_info['code']; + } else { + $language_code = $this->config->get('config_language'); + } + + $language = new Language($language_code); + $language->load($language_code); + $language->load('mail/affiliate_approve'); + + $subject = sprintf($language->get('text_subject'), $store_name); + + $data['text_welcome'] = sprintf($language->get('text_welcome'), $store_name); + + $data['login'] = $store_url . 'index.php?route=account/login'; + $data['store'] = $store_name; + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender($store_name); + $mail->setSubject($subject); + $mail->setText($this->load->view('mail/affiliate_approve', $data)); + $mail->send(); + } + } + + public function deny(&$route, &$args, &$output) { + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($args[0]); + + if ($customer_info) { + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8'); + $store_url = $store_info['url'] . 'index.php?route=account/login'; + } else { + $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); + $store_url = HTTP_CATALOG . 'index.php?route=account/login'; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']); + + if ($language_info) { + $language_code = $language_info['code']; + } else { + $language_code = $this->config->get('config_language'); + } + + $language = new Language($language_code); + $language->load($language_code); + $language->load('mail/affiliate_deny'); + + $subject = sprintf($language->get('text_subject'), $store_name); + + $data['text_welcome'] = sprintf($language->get('text_welcome'), $store_name); + + $data['contact'] = $store_url . 'index.php?route=information/contact'; + $data['store'] = $store_name; + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender($store_name); + $mail->setSubject($subject); + $mail->setText($this->load->view('mail/affiliate_deny', $data)); + $mail->send(); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/mail/customer.php b/public/admin/controller/mail/customer.php new file mode 100644 index 0000000..990d2d4 --- /dev/null +++ b/public/admin/controller/mail/customer.php @@ -0,0 +1,114 @@ +<?php +class ControllerMailCustomer extends Controller { + public function approve(&$route, &$args, &$output) { + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($args[0]); + + if ($customer_info) { + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8'); + $store_url = $store_info['url'] . 'index.php?route=account/login'; + } else { + $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); + $store_url = HTTP_CATALOG . 'index.php?route=account/login'; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']); + + if ($language_info) { + $language_code = $language_info['code']; + } else { + $language_code = $this->config->get('config_language'); + } + + $language = new Language($language_code); + $language->load($language_code); + $language->load('mail/customer_approve'); + + $subject = sprintf($language->get('text_subject'), $store_name); + + $data['text_welcome'] = sprintf($language->get('text_welcome'), $store_name); + + $data['login'] = $store_url . 'index.php?route=account/login'; + $data['store'] = $store_name; + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender($store_name); + $mail->setSubject($subject); + $mail->setText($this->load->view('mail/customer_approve', $data)); + $mail->send(); + } + } + + public function deny(&$route, &$args, &$output) { + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($args[0]); + + if ($customer_info) { + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8'); + $store_url = $store_info['url'] . 'index.php?route=account/login'; + } else { + $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); + $store_url = HTTP_CATALOG . 'index.php?route=account/login'; + } + + $this->load->model('localisation/language'); + + $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']); + + if ($language_info) { + $language_code = $language_info['code']; + } else { + $language_code = $this->config->get('config_language'); + } + + $language = new Language($language_code); + $language->load($language_code); + $language->load('mail/customer_deny'); + + $subject = sprintf($language->get('text_subject'), $store_name); + + $data['text_welcome'] = sprintf($language->get('text_welcome'), $store_name); + + $data['contact'] = $store_url . 'index.php?route=information/contact'; + $data['store'] = $store_name; + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender($store_name); + $mail->setSubject($subject); + $mail->setText($this->load->view('mail/customer_deny', $data)); + $mail->send(); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/mail/forgotten.php b/public/admin/controller/mail/forgotten.php new file mode 100644 index 0000000..c4f6029 --- /dev/null +++ b/public/admin/controller/mail/forgotten.php @@ -0,0 +1,26 @@ +<?php +class ControllerMailForgotten extends Controller { + public function index(&$route, &$args, &$output) { + $this->load->language('mail/forgotten'); + + $data['text_greeting'] = sprintf($this->language->get('text_greeting'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); + + $data['reset'] = str_replace('&', '&', $this->url->link('common/reset', 'code=' . $args[1], true)); + $data['ip'] = $this->request->server['REMOTE_ADDR']; + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($args[0]); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); + $mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')); + $mail->setText($this->load->view('mail/forgotten', $data)); + $mail->send(); + } +} diff --git a/public/admin/controller/mail/return.php b/public/admin/controller/mail/return.php new file mode 100644 index 0000000..a7d8ca4 --- /dev/null +++ b/public/admin/controller/mail/return.php @@ -0,0 +1,58 @@ +<?php +class ControllerMailReturn extends Controller { + public function index($route, $args, $output) { + if (isset($args[0])) { + $return_id = $args[0]; + } else { + $return_id = ''; + } + + if (isset($args[1])) { + $return_status_id = $args[1]; + } else { + $return_status_id = ''; + } + + if (isset($args[2])) { + $comment = $args[2]; + } else { + $comment = ''; + } + + if (isset($args[3])) { + $notify = $args[3]; + } else { + $notify = ''; + } + + if ($notify) { + $this->load->model('sale/return'); + + $return_info = $this->model_sale_return->getReturn($return_id); + + if ($return_info) { + $this->load->language('mail/return'); + + $data['return_id'] = $return_id; + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_modified'])); + $data['return_status'] = $return_info['return_status']; + $data['comment'] = strip_tags(html_entity_decode($comment, ENT_QUOTES, 'UTF-8')); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($return_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); + $mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $return_id)); + $mail->setText($this->load->view('mail/return', $data)); + $mail->send(); + } + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/mail/reward.php b/public/admin/controller/mail/reward.php new file mode 100644 index 0000000..8d72ad7 --- /dev/null +++ b/public/admin/controller/mail/reward.php @@ -0,0 +1,65 @@ +<?php +class ControllerMailReward extends Controller { + public function index($route, $args, $output) { + if (isset($args[0])) { + $customer_id = $args[0]; + } else { + $customer_id = ''; + } + + if (isset($args[1])) { + $description = $args[1]; + } else { + $description = ''; + } + + if (isset($args[2])) { + $points = $args[2]; + } else { + $points = ''; + } + + if (isset($args[3])) { + $order_id = $args[3]; + } else { + $order_id = 0; + } + + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($customer_id); + + if ($customer_info) { + $this->load->language('mail/reward'); + + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = $store_info['name']; + } else { + $store_name = $this->config->get('config_name'); + } + + $data['text_received'] = sprintf($this->language->get('text_received'), $points); + $data['text_total'] = sprintf($this->language->get('text_total'), $this->model_customer_customer->getRewardTotal($customer_id)); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->protocol = $this->config->get('config_mail_protocol'); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')); + $mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'))); + $mail->setText($this->load->view('mail/reward', $data)); + $mail->send(); + } + } +} diff --git a/public/admin/controller/mail/transaction.php b/public/admin/controller/mail/transaction.php new file mode 100644 index 0000000..5a3078a --- /dev/null +++ b/public/admin/controller/mail/transaction.php @@ -0,0 +1,64 @@ +<?php +class ControllerMailTransaction extends Controller { + public function index($route, $args, $output) { + if (isset($args[0])) { + $customer_id = $args[0]; + } else { + $customer_id = ''; + } + + if (isset($args[1])) { + $description = $args[1]; + } else { + $description = ''; + } + + if (isset($args[2])) { + $amount = $args[2]; + } else { + $amount = ''; + } + + if (isset($args[3])) { + $order_id = $args[3]; + } else { + $order_id = ''; + } + + $this->load->model('customer/customer'); + + $customer_info = $this->model_customer_customer->getCustomer($customer_id); + + if ($customer_info) { + $this->load->language('mail/transaction'); + + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($customer_info['store_id']); + + if ($store_info) { + $store_name = $store_info['name']; + } else { + $store_name = $this->config->get('config_name'); + } + + $data['text_received'] = sprintf($this->language->get('text_received'), $this->currency->format($amount, $this->config->get('config_currency'))); + $data['text_total'] = sprintf($this->language->get('text_total'), $this->currency->format($this->model_customer_customer->getTransactionTotal($customer_id), $this->config->get('config_currency'))); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($customer_info['email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')); + $mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'))); + $mail->setText($this->load->view('mail/transaction', $data)); + $mail->send(); + } + } +} diff --git a/public/admin/controller/marketing/contact.php b/public/admin/controller/marketing/contact.php new file mode 100644 index 0000000..d5aa1d2 --- /dev/null +++ b/public/admin/controller/marketing/contact.php @@ -0,0 +1,234 @@ +<?php +class ControllerMarketingContact extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketing/contact'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['cancel'] = $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'], true); + + $this->load->model('setting/store'); + + $data['stores'] = $this->model_setting_store->getStores(); + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketing/contact', $data)); + } + + public function send() { + $this->load->language('marketing/contact'); + + $json = array(); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if (!$this->user->hasPermission('modify', 'marketing/contact')) { + $json['error']['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['subject']) { + $json['error']['subject'] = $this->language->get('error_subject'); + } + + if (!$this->request->post['message']) { + $json['error']['message'] = $this->language->get('error_message'); + } + + if (!$json) { + $this->load->model('setting/store'); + + $store_info = $this->model_setting_store->getStore($this->request->post['store_id']); + + if ($store_info) { + $store_name = $store_info['name']; + } else { + $store_name = $this->config->get('config_name'); + } + + $this->load->model('setting/setting'); + $setting = $this->model_setting_setting->getSetting('config', $this->request->post['store_id']); + $store_email = isset($setting['config_email']) ? $setting['config_email'] : $this->config->get('config_email'); + + $this->load->model('customer/customer'); + + $this->load->model('customer/customer_group'); + + $this->load->model('sale/order'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $email_total = 0; + + $emails = array(); + + switch ($this->request->post['to']) { + case 'newsletter': + $customer_data = array( + 'filter_newsletter' => 1, + 'start' => ($page - 1) * 10, + 'limit' => 10 + ); + + $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); + + $results = $this->model_customer_customer->getCustomers($customer_data); + + foreach ($results as $result) { + $emails[] = $result['email']; + } + break; + case 'customer_all': + $customer_data = array( + 'start' => ($page - 1) * 10, + 'limit' => 10 + ); + + $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); + + $results = $this->model_customer_customer->getCustomers($customer_data); + + foreach ($results as $result) { + $emails[] = $result['email']; + } + break; + case 'customer_group': + $customer_data = array( + 'filter_customer_group_id' => $this->request->post['customer_group_id'], + 'start' => ($page - 1) * 10, + 'limit' => 10 + ); + + $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); + + $results = $this->model_customer_customer->getCustomers($customer_data); + + foreach ($results as $result) { + $emails[$result['customer_id']] = $result['email']; + } + break; + case 'customer': + if (!empty($this->request->post['customer'])) { + foreach ($this->request->post['customer'] as $customer_id) { + $customer_info = $this->model_customer_customer->getCustomer($customer_id); + + if ($customer_info) { + $emails[] = $customer_info['email']; + } + } + } + break; + case 'affiliate_all': + $affiliate_data = array( + 'filter_affiliate' => 1, + 'start' => ($page - 1) * 10, + 'limit' => 10 + ); + + $email_total = $this->model_customer_customer->getTotalCustomers($affiliate_data); + + $results = $this->model_customer_customer->getCustomers($affiliate_data); + + foreach ($results as $result) { + $emails[] = $result['email']; + } + break; + case 'affiliate': + if (!empty($this->request->post['affiliate'])) { + foreach ($this->request->post['affiliate'] as $affiliate_id) { + $affiliate_info = $this->model_customer_customer->getCustomer($affiliate_id); + + if ($affiliate_info) { + $emails[] = $affiliate_info['email']; + } + } + } + break; + case 'product': + if (isset($this->request->post['product'])) { + $email_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']); + + $results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $emails[] = $result['email']; + } + } + break; + } + + if ($emails) { + $json['success'] = $this->language->get('text_success'); + + $start = ($page - 1) * 10; + $end = $start + 10; + + $json['success'] = sprintf($this->language->get('text_sent'), $start, $email_total); + + if ($end < $email_total) { + $json['next'] = str_replace('&', '&', $this->url->link('marketing/contact/send', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true)); + } else { + $json['next'] = ''; + } + + $message = '<html dir="ltr" lang="en">' . "\n"; + $message .= ' <head>' . "\n"; + $message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n"; + $message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n"; + $message .= ' </head>' . "\n"; + $message .= ' <body>' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n"; + $message .= '</html>' . "\n"; + + foreach ($emails as $email) { + if (filter_var($email, FILTER_VALIDATE_EMAIL)) { + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($email); + $mail->setFrom($store_email); + $mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')); + $mail->setSubject(html_entity_decode($this->request->post['subject'], ENT_QUOTES, 'UTF-8')); + $mail->setHtml($message); + $mail->send(); + } + } + } else { + $json['error']['email'] = $this->language->get('error_email'); + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/marketing/coupon.php b/public/admin/controller/marketing/coupon.php new file mode 100644 index 0000000..f36ae79 --- /dev/null +++ b/public/admin/controller/marketing/coupon.php @@ -0,0 +1,556 @@ +<?php +class ControllerMarketingCoupon extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketing/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/coupon'); + + $this->getList(); + } + + public function add() { + $this->load->language('marketing/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/coupon'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_marketing_coupon->addCoupon($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('marketing/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/coupon'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_marketing_coupon->editCoupon($this->request->get['coupon_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('marketing/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/coupon'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $coupon_id) { + $this->model_marketing_coupon->deleteCoupon($coupon_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('marketing/coupon/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('marketing/coupon/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['coupons'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $coupon_total = $this->model_marketing_coupon->getTotalCoupons(); + + $results = $this->model_marketing_coupon->getCoupons($filter_data); + + foreach ($results as $result) { + $data['coupons'][] = array( + 'coupon_id' => $result['coupon_id'], + 'name' => $result['name'], + 'code' => $result['code'], + 'discount' => $result['discount'], + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'edit' => $this->url->link('marketing/coupon/edit', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_code'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_discount'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=discount' . $url, true); + $data['sort_date_start'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=date_start' . $url, true); + $data['sort_date_end'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=date_end' . $url, true); + $data['sort_status'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + + $url = ''; + + 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 = $coupon_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($coupon_total - $this->config->get('config_limit_admin'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $coupon_total, ceil($coupon_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketing/coupon_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['coupon_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['coupon_id'])) { + $data['coupon_id'] = $this->request->get['coupon_id']; + } else { + $data['coupon_id'] = 0; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + if (isset($this->error['date_start'])) { + $data['error_date_start'] = $this->error['date_start']; + } else { + $data['error_date_start'] = ''; + } + + if (isset($this->error['date_end'])) { + $data['error_date_end'] = $this->error['date_end']; + } else { + $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']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['coupon_id'])) { + $data['action'] = $this->url->link('marketing/coupon/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('marketing/coupon/edit', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $this->request->get['coupon_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['coupon_id']) && (!$this->request->server['REQUEST_METHOD'] != 'POST')) { + $coupon_info = $this->model_marketing_coupon->getCoupon($this->request->get['coupon_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($coupon_info)) { + $data['name'] = $coupon_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($coupon_info)) { + $data['code'] = $coupon_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } elseif (!empty($coupon_info)) { + $data['type'] = $coupon_info['type']; + } else { + $data['type'] = ''; + } + + if (isset($this->request->post['discount'])) { + $data['discount'] = $this->request->post['discount']; + } elseif (!empty($coupon_info)) { + $data['discount'] = $coupon_info['discount']; + } else { + $data['discount'] = ''; + } + + if (isset($this->request->post['logged'])) { + $data['logged'] = $this->request->post['logged']; + } elseif (!empty($coupon_info)) { + $data['logged'] = $coupon_info['logged']; + } else { + $data['logged'] = ''; + } + + if (isset($this->request->post['shipping'])) { + $data['shipping'] = $this->request->post['shipping']; + } elseif (!empty($coupon_info)) { + $data['shipping'] = $coupon_info['shipping']; + } else { + $data['shipping'] = ''; + } + + if (isset($this->request->post['total'])) { + $data['total'] = $this->request->post['total']; + } elseif (!empty($coupon_info)) { + $data['total'] = $coupon_info['total']; + } else { + $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_marketing_coupon->getCouponProducts($this->request->get['coupon_id']); + } else { + $products = array(); + } + + $this->load->model('catalog/product'); + + $data['coupon_product'] = array(); + + foreach ($products as $product_id) { + $product_info = $this->model_catalog_product->getProduct($product_id); + + if ($product_info) { + $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_marketing_coupon->getCouponCategories($this->request->get['coupon_id']); + } else { + $categories = array(); + } + + $this->load->model('catalog/category'); + + $data['coupon_category'] = array(); + + foreach ($categories as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $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'])) { + $data['date_start'] = $this->request->post['date_start']; + } elseif (!empty($coupon_info)) { + $data['date_start'] = ($coupon_info['date_start'] != '0000-00-00' ? $coupon_info['date_start'] : ''); + } else { + $data['date_start'] = date('Y-m-d', time()); + } + + if (isset($this->request->post['date_end'])) { + $data['date_end'] = $this->request->post['date_end']; + } elseif (!empty($coupon_info)) { + $data['date_end'] = ($coupon_info['date_end'] != '0000-00-00' ? $coupon_info['date_end'] : ''); + } else { + $data['date_end'] = date('Y-m-d', strtotime('+1 month')); + } + + if (isset($this->request->post['uses_total'])) { + $data['uses_total'] = $this->request->post['uses_total']; + } elseif (!empty($coupon_info)) { + $data['uses_total'] = $coupon_info['uses_total']; + } else { + $data['uses_total'] = 1; + } + + if (isset($this->request->post['uses_customer'])) { + $data['uses_customer'] = $this->request->post['uses_customer']; + } elseif (!empty($coupon_info)) { + $data['uses_customer'] = $coupon_info['uses_customer']; + } else { + $data['uses_customer'] = 1; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($coupon_info)) { + $data['status'] = $coupon_info['status']; + } else { + $data['status'] = true; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketing/coupon_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'marketing/coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 128)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['code']) < 3) || (utf8_strlen($this->request->post['code']) > 10)) { + $this->error['code'] = $this->language->get('error_code'); + } + + $coupon_info = $this->model_marketing_coupon->getCouponByCode($this->request->post['code']); + + if ($coupon_info) { + if (!isset($this->request->get['coupon_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } elseif ($coupon_info['coupon_id'] != $this->request->get['coupon_id']) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'marketing/coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function history() { + $this->load->language('marketing/coupon'); + + $this->load->model('marketing/coupon'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_marketing_coupon->getCouponHistories($this->request->get['coupon_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'amount' => $result['amount'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_marketing_coupon->getTotalCouponHistories($this->request->get['coupon_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('marketing/coupon/history', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $this->request->get['coupon_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf('Showing %d to %d of %d (%d Pages)', ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('marketing/coupon_history', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketing/marketing.php b/public/admin/controller/marketing/marketing.php new file mode 100644 index 0000000..083ad5e --- /dev/null +++ b/public/admin/controller/marketing/marketing.php @@ -0,0 +1,496 @@ +<?php +class ControllerMarketingMarketing extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketing/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/marketing'); + + $this->getList(); + } + + public function add() { + $this->load->language('marketing/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/marketing'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_marketing_marketing->addMarketing($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('marketing/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/marketing'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_marketing_marketing->editMarketing($this->request->get['marketing_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('marketing/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('marketing/marketing'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $marketing_id) { + $this->model_marketing_marketing->deleteMarketing($marketing_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_code'])) { + $filter_code = $this->request->get['filter_code']; + } else { + $filter_code = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('marketing/marketing/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('marketing/marketing/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['marketings'] = array(); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_code' => $filter_code, + 'filter_date_added' => $filter_date_added, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $marketing_total = $this->model_marketing_marketing->getTotalMarketings($filter_data); + + $results = $this->model_marketing_marketing->getMarketings($filter_data); + + foreach ($results as $result) { + $data['marketings'][] = array( + 'marketing_id' => $result['marketing_id'], + 'name' => $result['name'], + 'code' => $result['code'], + 'clicks' => $result['clicks'], + 'orders' => $result['orders'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('marketing/marketing/edit', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . '&sort=m.name' . $url, true); + $data['sort_code'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . '&sort=m.code' . $url, true); + $data['sort_date_added'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . '&sort=m.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $marketing_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($marketing_total - $this->config->get('config_limit_admin'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $marketing_total, ceil($marketing_total / $this->config->get('config_limit_admin'))); + + $data['filter_name'] = $filter_name; + $data['filter_code'] = $filter_code; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketing/marketing_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['marketing_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_code'])) { + $url .= '&filter_code=' . $this->request->get['filter_code']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['marketing_id'])) { + $data['action'] = $this->url->link('marketing/marketing/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('marketing/marketing/edit', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $this->request->get['marketing_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['marketing_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $marketing_info = $this->model_marketing_marketing->getMarketing($this->request->get['marketing_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['store'] = HTTP_CATALOG; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($marketing_info)) { + $data['name'] = $marketing_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($marketing_info)) { + $data['description'] = $marketing_info['description']; + } else { + $data['description'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($marketing_info)) { + $data['code'] = $marketing_info['code']; + } else { + $data['code'] = uniqid(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketing/marketing_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'marketing/marketing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['code']) { + $this->error['code'] = $this->language->get('error_code'); + } + + $marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->request->post['code']); + + if (!isset($this->request->get['marketing_id'])) { + if ($marketing_info) { + $this->error['code'] = $this->language->get('error_exists'); + } + } else { + if ($marketing_info && ($this->request->get['marketing_id'] != $marketing_info['marketing_id'])) { + $this->error['code'] = $this->language->get('error_exists'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'marketing/marketing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketplace/api.php b/public/admin/controller/marketplace/api.php new file mode 100644 index 0000000..d479016 --- /dev/null +++ b/public/admin/controller/marketplace/api.php @@ -0,0 +1,39 @@ +<?php +class ControllerMarketplaceApi extends Controller { + public function index() { + $this->load->language('marketplace/api'); + + $data['user_token'] = $this->session->data['user_token']; + + $this->response->setOutput($this->load->view('marketplace/api', $data)); + } + + public function save() { + $this->load->language('marketplace/api'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'marketplace/api')) { + $json['error']['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['opencart_username']) { + $json['error']['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['opencart_secret']) { + $json['error']['secret'] = $this->language->get('error_secret'); + } + + if (!$json) { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('opencart', $this->request->post); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketplace/event.php b/public/admin/controller/marketplace/event.php new file mode 100644 index 0000000..c261da0 --- /dev/null +++ b/public/admin/controller/marketplace/event.php @@ -0,0 +1,260 @@ +<?php +class ControllerMarketplaceEvent extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketplace/event'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/event'); + + $this->getList(); + } + + public function enable() { + $this->load->language('marketplace/event'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/event'); + + if (isset($this->request->get['event_id']) && $this->validate()) { + $this->model_setting_event->enableEvent($this->request->get['event_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function disable() { + $this->load->language('marketplace/event'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/event'); + + if (isset($this->request->get['event_id']) && $this->validate()) { + $this->model_setting_event->disableEvent($this->request->get['event_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function delete() { + $this->load->language('marketplace/event'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/event'); + + if (isset($this->request->post['selected']) && $this->validate()) { + foreach ($this->request->post['selected'] as $event_id) { + $this->model_setting_event->deleteEvent($event_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'code'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['delete'] = $this->url->link('marketplace/event/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['events'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $event_total = $this->model_setting_event->getTotalEvents(); + + $results = $this->model_setting_event->getEvents($filter_data); + + foreach ($results as $result) { + $data['events'][] = array( + 'event_id' => $result['event_id'], + 'code' => $result['code'], + 'trigger' => $result['trigger'], + 'action' => $result['action'], + 'sort_order' => $result['sort_order'], + 'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'enable' => $this->url->link('marketplace/event/enable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id'] . $url, true), + 'disable' => $this->url->link('marketplace/event/disable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id'] . $url, true), + 'enabled' => $result['status'] + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_code'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_sort_order'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true); + $data['sort_status'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + + $url = ''; + + 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 = $event_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($event_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($event_total - $this->config->get('config_limit_admin'))) ? $event_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $event_total, ceil($event_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/event', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'marketplace/event')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketplace/extension.php b/public/admin/controller/marketplace/extension.php new file mode 100644 index 0000000..046fd10 --- /dev/null +++ b/public/admin/controller/marketplace/extension.php @@ -0,0 +1,57 @@ +<?php +class ControllerMarketplaceExtension extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketplace/extension'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['type'])) { + $data['type'] = $this->request->get['type']; + } else { + $data['type'] = ''; + } + + $data['categories'] = array(); + + $files = glob(DIR_APPLICATION . 'controller/extension/extension/*.php', GLOB_BRACE); + + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/extension/' . $extension, 'extension'); + + if ($this->user->hasPermission('access', 'extension/extension/' . $extension)) { + $files = glob(DIR_APPLICATION . 'controller/extension/' . $extension . '/*.php', GLOB_BRACE); + + $data['categories'][] = array( + 'code' => $extension, + 'text' => $this->language->get('extension')->get('heading_title') . ' (' . count($files) .')', + 'href' => $this->url->link('extension/extension/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/extension', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketplace/install.php b/public/admin/controller/marketplace/install.php new file mode 100644 index 0000000..5d3ccb9 --- /dev/null +++ b/public/admin/controller/marketplace/install.php @@ -0,0 +1,520 @@ +<?php +class ControllerMarketplaceInstall extends Controller { + public function install() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (isset($this->request->get['extension_install_id'])) { + $extension_install_id = $this->request->get['extension_install_id']; + } else { + $extension_install_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + // Make sure the file name is stored in the session. + if (!isset($this->session->data['install'])) { + $json['error'] = $this->language->get('error_file'); + } elseif (!is_file(DIR_UPLOAD . $this->session->data['install'] . '.tmp')) { + $json['error'] = $this->language->get('error_file'); + } + + if (!$json) { + $json['text'] = $this->language->get('text_unzip'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/unzip', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true)); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function unzip() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (isset($this->request->get['extension_install_id'])) { + $extension_install_id = $this->request->get['extension_install_id']; + } else { + $extension_install_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!isset($this->session->data['install'])) { + $json['error'] = $this->language->get('error_file'); + } elseif (!is_file(DIR_UPLOAD . $this->session->data['install'] . '.tmp')) { + $json['error'] = $this->language->get('error_file'); + } + + // Sanitize the filename + if (!$json) { + $file = DIR_UPLOAD . $this->session->data['install'] . '.tmp'; + + // Unzip the files + $zip = new ZipArchive(); + + if ($zip->open($file)) { + $zip->extractTo(DIR_UPLOAD . 'tmp-' . $this->session->data['install']); + $zip->close(); + } else { + $json['error'] = $this->language->get('error_unzip'); + } + + // Remove Zip + unlink($file); + + $json['text'] = $this->language->get('text_move'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/move', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true)); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function move() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (isset($this->request->get['extension_install_id'])) { + $extension_install_id = $this->request->get['extension_install_id']; + } else { + $extension_install_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!isset($this->session->data['install'])) { + $json['error'] = $this->language->get('error_directory'); + } elseif (!is_dir(DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/')) { + $json['error'] = $this->language->get('error_directory'); + } + + if (!$json) { + $directory = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/'; + + if (is_dir($directory . 'upload/')) { + $files = array(); + + // Get a list of files ready to upload + $path = array($directory . 'upload/*'); + + while (count($path) != 0) { + $next = array_shift($path); + + foreach ((array)glob($next) as $file) { + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + $files[] = $file; + } + } + + // A list of allowed directories to be written to + $allowed = array( + 'admin/controller/extension/', + 'admin/language/', + 'admin/model/extension/', + 'admin/view/image/', + 'admin/view/javascript/', + 'admin/view/stylesheet/', + 'admin/view/template/extension/', + 'catalog/controller/extension/', + 'catalog/language/', + 'catalog/model/extension/', + 'catalog/view/javascript/', + 'catalog/view/theme/', + 'system/config/', + 'system/library/', + 'image/catalog/' + ); + + // First we need to do some checks + foreach ($files as $file) { + $destination = str_replace('\\', '/', substr($file, strlen($directory . 'upload/'))); + + $safe = false; + + foreach ($allowed as $value) { + if (strlen($destination) < strlen($value) && substr($value, 0, strlen($destination)) == $destination) { + $safe = true; + + break; + } + + if (strlen($destination) > strlen($value) && substr($destination, 0, strlen($value)) == $value) { + $safe = true; + + break; + } + } + + if ($safe) { + // Check if the copy location exists or not + if (substr($destination, 0, 5) == 'admin') { + $destination = DIR_APPLICATION . substr($destination, 6); + } + + if (substr($destination, 0, 7) == 'catalog') { + $destination = DIR_CATALOG . substr($destination, 8); + } + + if (substr($destination, 0, 5) == 'image') { + $destination = DIR_IMAGE . substr($destination, 6); + } + + if (substr($destination, 0, 6) == 'system') { + $destination = DIR_SYSTEM . substr($destination, 7); + } + } else { + $json['error'] = sprintf($this->language->get('error_allowed'), $destination); + + break; + } + } + + if (!$json) { + $this->load->model('setting/extension'); + + foreach ($files as $file) { + $destination = str_replace('\\', '/', substr($file, strlen($directory . 'upload/'))); + + $path = ''; + + if (substr($destination, 0, 5) == 'admin') { + $path = DIR_APPLICATION . substr($destination, 6); + } + + if (substr($destination, 0, 7) == 'catalog') { + $path = DIR_CATALOG . substr($destination, 8); + } + + if (substr($destination, 0, 5) == 'image') { + $path = DIR_IMAGE . substr($destination, 6); + } + + if (substr($destination, 0, 6) == 'system') { + $path = DIR_SYSTEM . substr($destination, 7); + } + + if (is_dir($file) && !is_dir($path)) { + if (mkdir($path, 0777)) { + $this->model_setting_extension->addExtensionPath($extension_install_id, $destination); + } + } + + if (is_file($file)) { + if (rename($file, $path)) { + $this->model_setting_extension->addExtensionPath($extension_install_id, $destination); + } + } + } + } + } + } + + if (!$json) { + $json['text'] = $this->language->get('text_xml'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/xml', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true)); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function xml() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (isset($this->request->get['extension_install_id'])) { + $extension_install_id = $this->request->get['extension_install_id']; + } else { + $extension_install_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!isset($this->session->data['install'])) { + $json['error'] = $this->language->get('error_directory'); + } elseif (!is_dir(DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/')) { + $json['error'] = $this->language->get('error_directory'); + } + + if (!$json) { + $file = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/install.xml'; + + if (is_file($file)) { + $this->load->model('setting/modification'); + + // If xml file just put it straight into the DB + $xml = file_get_contents($file); + + if ($xml) { + try { + $dom = new DOMDocument('1.0', 'UTF-8'); + $dom->loadXml($xml); + + $name = $dom->getElementsByTagName('name')->item(0); + + if ($name) { + $name = $name->nodeValue; + } else { + $name = ''; + } + + $code = $dom->getElementsByTagName('code')->item(0); + + if ($code) { + $code = $code->nodeValue; + + // Check to see if the modification is already installed or not. + $modification_info = $this->model_setting_modification->getModificationByCode($code); + + if ($modification_info) { + $this->model_setting_modification->deleteModification($modification_info['modification_id']); + } + } else { + $json['error'] = $this->language->get('error_code'); + } + + $author = $dom->getElementsByTagName('author')->item(0); + + if ($author) { + $author = $author->nodeValue; + } else { + $author = ''; + } + + $version = $dom->getElementsByTagName('version')->item(0); + + if ($version) { + $version = $version->nodeValue; + } else { + $version = ''; + } + + $link = $dom->getElementsByTagName('link')->item(0); + + if ($link) { + $link = $link->nodeValue; + } else { + $link = ''; + } + + if (!$json) { + + + $modification_data = array( + 'extension_install_id' => $extension_install_id, + 'name' => $name, + 'code' => $code, + 'author' => $author, + 'version' => $version, + 'link' => $link, + 'xml' => $xml, + 'status' => 1 + ); + + $this->model_setting_modification->addModification($modification_data); + } + } catch(Exception $exception) { + $json['error'] = sprintf($this->language->get('error_exception'), $exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine()); + } + } + } + } + + if (!$json) { + $json['text'] = $this->language->get('text_remove'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/remove', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function remove() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!isset($this->session->data['install'])) { + $json['error'] = $this->language->get('error_directory'); + } + + if (!$json) { + $directory = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/'; + + if (is_dir($directory)) { + // Get a list of files ready to upload + $files = array(); + + $path = array($directory); + + while (count($path) != 0) { + $next = array_shift($path); + + // We have to use scandir function because glob will not pick up dot files. + foreach (array_diff(scandir($next), array('.', '..')) as $file) { + $file = $next . '/' . $file; + + if (is_dir($file)) { + $path[] = $file; + } + + $files[] = $file; + } + } + + rsort($files); + + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } elseif (is_dir($file)) { + rmdir($file); + } + } + + if (is_dir($directory)) { + rmdir($directory); + } + } + + $file = DIR_UPLOAD . $this->session->data['install'] . '.tmp'; + + if (is_file($file)) { + unlink($file); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function uninstall() { + $this->load->language('marketplace/install'); + + $json = array(); + + if (isset($this->request->get['extension_install_id'])) { + $extension_install_id = $this->request->get['extension_install_id']; + } else { + $extension_install_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/install')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + $this->load->model('setting/extension'); + + $results = $this->model_setting_extension->getExtensionPathsByExtensionInstallId($extension_install_id); + + rsort($results); + + foreach ($results as $result) { + $source = ''; + + // Check if the copy location exists or not + if (substr($result['path'], 0, 5) == 'admin') { + $source = DIR_APPLICATION . substr($result['path'], 6); + } + + if (substr($result['path'], 0, 7) == 'catalog') { + $source = DIR_CATALOG . substr($result['path'], 8); + } + + if (substr($result['path'], 0, 5) == 'image') { + $source = DIR_IMAGE . substr($result['path'], 6); + } + + if (substr($result['path'], 0, 14) == 'system/library') { + $source = DIR_SYSTEM . 'library/' . substr($result['path'], 15); + } + + if (is_file($source)) { + unlink($source); + } + + if (is_dir($source)) { + // Get a list of files ready to upload + $files = array(); + + $path = array($source); + + while (count($path) != 0) { + $next = array_shift($path); + + // We have to use scandir function because glob will not pick up dot files. + foreach (array_diff(scandir($next), array('.', '..')) as $file) { + $file = $next . '/' . $file; + + if (is_dir($file)) { + $path[] = $file; + } + + $files[] = $file; + } + } + + rsort($files); + + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } elseif (is_dir($file)) { + rmdir($file); + } + } + + if (is_file($source)) { + unlink($source); + } + + if (is_dir($source)) { + rmdir($source); + } + } + + $this->model_setting_extension->deleteExtensionPath($result['extension_path_id']); + } + + // Remove the install + $this->model_setting_extension->deleteExtensionInstall($extension_install_id); + + // Remove any xml modifications + $this->load->model('setting/modification'); + + $this->model_setting_modification->deleteModificationsByExtensionInstallId($extension_install_id); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/marketplace/installer.php b/public/admin/controller/marketplace/installer.php new file mode 100644 index 0000000..5666a6d --- /dev/null +++ b/public/admin/controller/marketplace/installer.php @@ -0,0 +1,172 @@ +<?php +class ControllerMarketplaceInstaller extends Controller { + public function index() { + $this->load->language('marketplace/installer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/installer', $data)); + } + + public function history() { + $this->load->language('marketplace/installer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $this->load->model('setting/extension'); + + $results = $this->model_setting_extension->getExtensionInstalls(($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'extension_install_id' => $result['extension_install_id'], + 'filename' => $result['filename'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_setting_extension->getTotalExtensionInstalls(); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('marketplace/installer/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('marketplace/installer_history', $data)); + } + + public function upload() { + $this->load->language('marketplace/installer'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'marketplace/installer')) { + $json['error'] = $this->language->get('error_permission'); + } + + // Check if there is a install zip already there + $files = glob(DIR_UPLOAD . '*.tmp'); + + foreach ($files as $file) { + if (is_file($file) && (filectime($file) < (time() - 5))) { + unlink($file); + } + + if (is_file($file)) { + $json['error'] = $this->language->get('error_install'); + + break; + } + } + + // Check for any install directories + $directories = glob(DIR_UPLOAD . 'tmp-*'); + + foreach ($directories as $directory) { + if (is_dir($directory) && (filectime($directory) < (time() - 5))) { + // Get a list of files ready to upload + $files = array(); + + $path = array($directory); + + while (count($path) != 0) { + $next = array_shift($path); + + // We have to use scandir function because glob will not pick up dot files. + foreach (array_diff(scandir($next), array('.', '..')) as $file) { + $file = $next . '/' . $file; + + if (is_dir($file)) { + $path[] = $file; + } + + $files[] = $file; + } + } + + rsort($files); + + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } elseif (is_dir($file)) { + rmdir($file); + } + } + + rmdir($directory); + } + + if (is_dir($directory)) { + $json['error'] = $this->language->get('error_install'); + + break; + } + } + + if (isset($this->request->files['file']['name'])) { + if (substr($this->request->files['file']['name'], -10) != '.ocmod.zip') { + $json['error'] = $this->language->get('error_filetype'); + } + + 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) { + $this->session->data['install'] = token(10); + + $file = DIR_UPLOAD . $this->session->data['install'] . '.tmp'; + + move_uploaded_file($this->request->files['file']['tmp_name'], $file); + + if (is_file($file)) { + $this->load->model('setting/extension'); + + $extension_install_id = $this->model_setting_extension->addExtensionInstall($this->request->files['file']['name']); + + $json['text'] = $this->language->get('text_install'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true)); + } else { + $json['error'] = $this->language->get('error_file'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/marketplace/marketplace.php b/public/admin/controller/marketplace/marketplace.php new file mode 100644 index 0000000..914b1df --- /dev/null +++ b/public/admin/controller/marketplace/marketplace.php @@ -0,0 +1,1111 @@ +<?php +class ControllerMarketplaceMarketplace extends Controller { + public function index() { + $this->load->language('marketplace/marketplace'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->request->get['filter_search'])) { + $filter_search = $this->request->get['filter_search']; + } else { + $filter_search = ''; + } + + if (isset($this->request->get['filter_category'])) { + $filter_category = $this->request->get['filter_category']; + } else { + $filter_category = ''; + } + + if (isset($this->request->get['filter_license'])) { + $filter_license = $this->request->get['filter_license']; + } else { + $filter_license = ''; + } + + if (isset($this->request->get['filter_rating'])) { + $filter_rating = $this->request->get['filter_rating']; + } else { + $filter_rating = ''; + } + + if (isset($this->request->get['filter_member_type'])) { + $filter_member_type = $this->request->get['filter_member_type']; + } else { + $filter_member_type = ''; + } + + if (isset($this->request->get['filter_member'])) { + $filter_member = $this->request->get['filter_member']; + } else { + $filter_member = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'date_modified'; + } + + if (isset($this->request->get['page'])) { + $page = (int)$this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $time = time(); + + // We create a hash from the data in a similar method to how amazon does things. + $string = 'marketplace/api/list' . "\n"; + $string .= $this->config->get('opencart_username') . "\n"; + $string .= $this->request->server['HTTP_HOST'] . "\n"; + $string .= VERSION . "\n"; + $string .= $time . "\n"; + + $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), 1)); + + $url = '&username=' . urlencode($this->config->get('opencart_username')); + $url .= '&domain=' . $this->request->server['HTTP_HOST']; + $url .= '&version=' . urlencode(VERSION); + $url .= '&time=' . $time; + $url .= '&signature=' . rawurlencode($signature); + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . urlencode($this->request->get['filter_search']); + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api' . $url); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, 1); + + $response = curl_exec($curl); + + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + curl_close($curl); + + $response_info = json_decode($response, true); + + $extension_total = $response_info['extension_total']; + + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['promotions'] = array(); + + if ($response_info['promotions'] && $page == 1) { + foreach ($response_info['promotions'] as $result) { + $data['promotions'][] = array( + 'name' => $result['name'], + 'description' => $result['description'], + 'image' => $result['image'], + 'license' => $result['license'], + 'price' => $result['price'], + 'rating' => $result['rating'], + 'rating_total' => $result['rating_total'], + 'href' => $this->url->link('marketplace/marketplace/info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . $url, true) + ); + } + } + + $data['extensions'] = array(); + + if ($response_info['extensions']) { + foreach ($response_info['extensions'] as $result) { + $data['extensions'][] = array( + 'name' => utf8_decode($result['name']), + 'description' => utf8_decode($result['description']), + 'image' => $result['image'], + 'license' => $result['license'], + 'price' => $result['price'], + 'rating' => $result['rating'], + 'rating_total' => $result['rating_total'], + 'href' => $this->url->link('marketplace/marketplace/info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . $url, true) + ); + } + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($response_info['error'])) { + $data['error_signature'] = $response_info['error']; + } else { + $data['error_signature'] = ''; + } + + // Categories + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + $data['categories'] = array(); + + $data['categories'][] = array( + 'text' => $this->language->get('text_all'), + 'value' => '', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_theme'), + 'value' => 'theme', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=theme' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_marketplace'), + 'value' => 'marketplace', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=marketplace' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_language'), + 'value' => 'language', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=language' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_payment'), + 'value' => 'payment', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=payment' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_shipping'), + 'value' => 'shipping', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=shipping' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_module'), + 'value' => 'module', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=module' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_total'), + 'value' => 'total', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=total' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_feed'), + 'value' => 'feed', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=feed' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_report'), + 'value' => 'report', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=report' . $url, true) + ); + + $data['categories'][] = array( + 'text' => $this->language->get('text_other'), + 'value' => 'other', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=other' . $url, true) + ); + + // Licenses + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['licenses'] = array(); + + $data['licenses'][] = array( + 'text' => $this->language->get('text_all'), + 'value' => '', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['licenses'][] = array( + 'text' => $this->language->get('text_free'), + 'value' => 'free', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=free' . $url, true) + ); + + $data['licenses'][] = array( + 'text' => $this->language->get('text_paid'), + 'value' => 'paid', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=paid' . $url, true) + ); + + + $data['licenses'][] = array( + 'text' => $this->language->get('text_purchased'), + 'value' => 'purchased', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=purchased' . $url, true) + ); + + // Sort + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + $data['sorts'] = array(); + + $data['sorts'][] = array( + 'text' => $this->language->get('text_date_modified'), + 'value' => 'date_modified', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=date_modified') + ); + + $data['sorts'][] = array( + 'text' => $this->language->get('text_date_added'), + 'value' => 'date_added', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=date_added') + ); + + $data['sorts'][] = array( + 'text' => $this->language->get('text_rating'), + 'value' => 'rating', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=rating') + ); + + + $data['sorts'][] = array( + 'text' => $this->language->get('text_name'), + 'value' => 'name', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=name') + ); + + $data['sorts'][] = array( + 'text' => $this->language->get('text_price'), + 'value' => 'price', + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=price') + ); + + // Pagination + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_rating'])) { + $url .= '&filter_rating=' . $this->request->get['filter_rating']; + } + + if (isset($this->request->get['filter_member_type'])) { + $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; + } + + if (isset($this->request->get['filter_member'])) { + $url .= '&filter_member=' . $this->request->get['filter_member']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + $pagination = new Pagination(); + $pagination->total = $extension_total; + $pagination->page = $page; + $pagination->limit = 12; + $pagination->url = $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['filter_search'] = $filter_search; + $data['filter_category'] = $filter_category; + $data['filter_license'] = $filter_license; + $data['filter_member_type'] = $filter_member_type; + $data['filter_rating'] = $filter_rating; + $data['sort'] = $sort; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/marketplace_list', $data)); + } + + public function info() { + if (isset($this->request->get['extension_id'])) { + $extension_id = $this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + $time = time(); + + // We create a hash from the data in a similar method to how amazon does things. + $string = 'marketplace/api/info' . "\n"; + $string .= $this->config->get('opencart_username') . "\n"; + $string .= $this->request->server['HTTP_HOST'] . "\n"; + $string .= VERSION . "\n"; + $string .= $extension_id . "\n"; + $string .= $time . "\n"; + + $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), 1)); + + $url = '&username=' . urlencode($this->config->get('opencart_username')); + $url .= '&domain=' . $this->request->server['HTTP_HOST']; + $url .= '&version=' . urlencode(VERSION); + $url .= '&extension_id=' . $extension_id; + $url .= '&time=' . $time; + $url .= '&signature=' . rawurlencode($signature); + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/info' . $url); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, 1); + + $response = curl_exec($curl); + + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + curl_close($curl); + + $response_info = json_decode($response, true); + + if ($response_info) { + $this->load->language('marketplace/marketplace'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($response_info['error'])) { + $data['error_signature'] = $response_info['error']; + } else { + $data['error_signature'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_search'])) { + $url .= '&filter_search=' . $this->request->get['filter_search']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_license'])) { + $url .= '&filter_license=' . $this->request->get['filter_license']; + } + + if (isset($this->request->get['filter_username'])) { + $url .= '&filter_username=' . $this->request->get['filter_username']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['cancel'] = $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $this->load->helper('bbcode'); + + $data['banner'] = $response_info['banner']; + + $data['extension_id'] = (int)$this->request->get['extension_id']; + $data['name'] = $response_info['name']; + $data['description'] = $response_info['description']; + $data['documentation'] = $response_info['documentation']; + $data['price'] = $response_info['price']; + $data['license'] = $response_info['license']; + $data['license_period'] = $response_info['license_period']; + $data['purchased'] = $response_info['purchased']; + $data['rating'] = $response_info['rating']; + $data['rating_total'] = $response_info['rating_total']; + $data['downloaded'] = $response_info['downloaded']; + $data['sales'] = $response_info['sales']; + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($response_info['date_added'])); + $data['date_modified'] = date($this->language->get('date_format_short'), strtotime($response_info['date_modified'])); + + $data['member_username'] = $response_info['member_username']; + $data['member_image'] = $response_info['member_image']; + $data['member_date_added'] = $response_info['member_date_added']; + $data['filter_member'] = $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_member=' . $response_info['member_username']); + + $data['comment_total'] = $response_info['comment_total']; + + $data['images'] = array(); + + foreach ($response_info['images'] as $result) { + $data['images'][] = array( + 'thumb' => $result['thumb'], + 'popup' => $result['popup'] + ); + } + + $this->load->model('setting/extension'); + + $data['downloads'] = array(); + + if ($response_info['downloads']) { + foreach ($response_info['downloads'] as $result) { + $extension_install_info = $this->model_setting_extension->getExtensionInstallByExtensionDownloadId($result['extension_download_id']); + + if ($extension_install_info) { + $extension_install_id = $extension_install_info['extension_install_id']; + } else { + $extension_install_id = 0; + } + + $data['downloads'][] = array( + 'extension_download_id' => $result['extension_download_id'], + 'extension_install_id' => $extension_install_id, + 'name' => $result['name'], + 'filename' => $result['filename'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'status' => $result['status'] + ); + } + } + + $this->document->addStyle('view/javascript/jquery/magnific/magnific-popup.css'); + $this->document->addScript('view/javascript/jquery/magnific/jquery.magnific-popup.min.js'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/marketplace_info', $data)); + } else { + return new Action('error/not_found'); + } + } + + public function purchase() { + $this->load->language('marketplace/marketplace'); + + $json = array(); + + if (isset($this->request->get['extension_id'])) { + $extension_id = $this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { + $json['error'] = $this->language->get('error_opencart'); + } + + if (!$this->request->post['pin']) { + $json['error'] = $this->language->get('error_pin'); + } + + if (!$json) { + $time = time(); + + // We create a hash from the data in a similar method to how amazon does things. + $string = 'marketplace/api/purchase' . "\n"; + $string .= $this->config->get('opencart_username') . "\n"; + $string .= $this->request->server['HTTP_HOST'] . "\n"; + $string .= VERSION . "\n"; + $string .= $extension_id . "\n"; + $string .= $this->request->post['pin'] . "\n"; + $string .= $time . "\n"; + + $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), 1)); + + $url = '&username=' . urlencode($this->config->get('opencart_username')); + $url .= '&domain=' . $this->request->server['HTTP_HOST']; + $url .= '&version=' . urlencode(VERSION); + $url .= '&extension_id=' . $extension_id; + $url .= '&time=' . $time; + $url .= '&signature=' . rawurlencode($signature); + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/purchase' . $url); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); + + $response = curl_exec($curl); + + curl_close($curl); + + $response_info = json_decode($response, true); + + if (isset($response_info['success'])) { + $json['success'] = $response_info['success']; + } elseif (isset($response_info['error'])) { + $json['error'] = $response_info['error']; + } else { + $json['error'] = $this->language->get('error_purchase'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function download() { + $this->load->language('marketplace/marketplace'); + + $json = array(); + + if (isset($this->request->get['extension_id'])) { + $extension_id = $this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + if (isset($this->request->get['extension_download_id'])) { + $extension_download_id = $this->request->get['extension_download_id']; + } else { + $extension_download_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { + $json['error'] = $this->language->get('error_permission'); + } + + // Check if there is a install zip already there + $files = glob(DIR_UPLOAD . '*.tmp'); + + foreach ($files as $file) { + if (is_file($file) && (filectime($file) < (time() - 5))) { + unlink($file); + } + + if (is_file($file)) { + $json['error'] = $this->language->get('error_install'); + + break; + } + } + + // Check for any install directories + $directories = glob(DIR_UPLOAD . 'tmp-*'); + + foreach ($directories as $directory) { + if (is_dir($directory) && (filectime($directory) < (time() - 5))) { + // Get a list of files ready to upload + $files = array(); + + $path = array($directory); + + while (count($path) != 0) { + $next = array_shift($path); + + // We have to use scandir function because glob will not pick up dot files. + foreach (array_diff(scandir($next), array('.', '..')) as $file) { + $file = $next . '/' . $file; + + if (is_dir($file)) { + $path[] = $file; + } + + $files[] = $file; + } + } + + rsort($files); + + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } elseif (is_dir($file)) { + rmdir($file); + } + } + + rmdir($directory); + } + + if (is_dir($directory)) { + $json['error'] = $this->language->get('error_install'); + + break; + } + } + + if (!$json) { + $time = time(); + + // We create a hash from the data in a similar method to how amazon does things. + $string = 'marketplace/api/download' . "\n"; + $string .= $this->config->get('opencart_username') . "\n"; + $string .= $this->request->server['HTTP_HOST'] . "\n"; + $string .= VERSION . "\n"; + $string .= $extension_id . "\n"; + $string .= $extension_download_id . "\n"; + $string .= $time . "\n"; + + $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), 1)); + + $url = '&username=' . urlencode($this->config->get('opencart_username')); + $url .= '&domain=' . $this->request->server['HTTP_HOST']; + $url .= '&version=' . urlencode(VERSION); + $url .= '&extension_id=' . $extension_id; + $url .= '&extension_download_id=' . $extension_download_id; + $url .= '&time=' . $time; + $url .= '&signature=' . rawurlencode($signature); + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/download&extension_download_id=' . $extension_download_id . $url); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); + + $response = curl_exec($curl); + + $response_info = json_decode($response, true); + + curl_close($curl); + + if (isset($response_info['download'])) { + if (substr($response_info['filename'], -10) == '.ocmod.zip') { + $this->session->data['install'] = token(10); + + $download = file_get_contents($response_info['download']); + + $handle = fopen(DIR_UPLOAD . $this->session->data['install'] . '.tmp', 'w'); + + fwrite($handle, $download); + + fclose($handle); + + $this->load->model('setting/extension'); + + $json['extension_install_id'] = $this->model_setting_extension->addExtensionInstall($response_info['extension'], $extension_download_id); + + $json['text'] = $this->language->get('text_install'); + + $json['next'] = str_replace('&', '&', $this->url->link('marketplace/install/install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $json['extension_install_id'], true)); + } else { + $json['redirect'] = $response_info['download']; + } + } elseif (isset($response_info['error'])) { + $json['error'] = $response_info['error']; + } else { + $json['error'] = $this->language->get('error_download'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function addComment() { + $this->load->language('marketplace/marketplace'); + + $json = array(); + + if (isset($this->request->get['extension_id'])) { + $extension_id = $this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + if (isset($this->request->get['parent_id'])) { + $parent_id = $this->request->get['parent_id']; + } else { + $parent_id = 0; + } + + if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { + $json['error'] = $this->language->get('error_opencart'); + } + + if (!$json) { + $time = time(); + + // We create a hash from the data in a similar method to how amazon does things. + $string = 'marketplace/api/addcomment' . "\n"; + $string .= urlencode($this->config->get('opencart_username')) . "\n"; + $string .= $this->request->server['HTTP_HOST'] . "\n"; + $string .= urlencode(VERSION) . "\n"; + $string .= $extension_id . "\n"; + $string .= $parent_id . "\n"; + $string .= urlencode(base64_encode($this->request->post['comment'])) . "\n"; + $string .= $time . "\n"; + + $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), 1)); + + $url = '&username=' . $this->config->get('opencart_username'); + $url .= '&domain=' . $this->request->server['HTTP_HOST']; + $url .= '&version=' . VERSION; + $url .= '&extension_id=' . $extension_id; + $url .= '&parent_id=' . $parent_id; + $url .= '&time=' . $time; + $url .= '&signature=' . rawurlencode($signature); + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/addcomment&extension_id=' . $extension_id . $url); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, array('comment' => $this->request->post['comment'])); + + $response = curl_exec($curl); + + curl_close($curl); + + $response_info = json_decode($response, true); + + if (isset($response_info['success'])) { + $json['success'] = $response_info['success']; + } elseif (isset($response_info['error'])) { + $json['error'] = $response_info['error']; + } else { + $json['error'] = $this->language->get('error_comment'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function comment() { + $this->load->language('marketplace/marketplace'); + + if (isset($this->request->get['extension_id'])) { + $extension_id = (int)$this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['button_more'] = $this->language->get('button_more'); + $data['button_reply'] = $this->language->get('button_reply'); + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/comment&extension_id=' . $extension_id . '&page=' . $page); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); + + $response = curl_exec($curl); + + curl_close($curl); + + $json = json_decode($response, true); + + $data['comments'] = array(); + + $comment_total = $json['comment_total']; + + if ($json['comments']) { + $results = $json['comments']; + + foreach ($results as $result) { + if ($result['reply_total'] > 5) { + $next = $this->url->link('marketplace/marketplace/reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id'] . '&page=2'); + } else { + $next = ''; + } + + $data['comments'][] = array( + 'extension_comment_id' => $result['extension_comment_id'], + 'member' => $result['member'], + 'image' => $result['image'], + 'comment' => $result['comment'], + 'date_added' => $result['date_added'], + 'reply' => $result['reply'], + 'add' => $this->url->link('marketplace/marketplace/addcomment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id']), + 'refresh' => $this->url->link('marketplace/marketplace/reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id'] . '&page=1'), + 'next' => $next + ); + } + } + + $pagination = new Pagination(); + $pagination->total = $comment_total; + $pagination->page = $page; + $pagination->limit = 20; + $pagination->url = $this->url->link('marketplace/marketplace/comment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&page={page}'); + + $data['pagination'] = $pagination->render(); + + $data['refresh'] = $this->url->link('marketplace/marketplace/comment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&page=' . $page); + + $this->response->setOutput($this->load->view('marketplace/marketplace_comment', $data)); + } + + public function reply() { + $this->load->language('marketplace/marketplace'); + + if (isset($this->request->get['extension_id'])) { + $extension_id = $this->request->get['extension_id']; + } else { + $extension_id = 0; + } + + if (isset($this->request->get['parent_id'])) { + $parent_id = $this->request->get['parent_id']; + } else { + $parent_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $curl = curl_init(OPENCART_SERVER . 'index.php?route=marketplace/api/comment&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . $page); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); + + $response = curl_exec($curl); + + $json = json_decode($response, true); + + $data['replies'] = array(); + + $reply_total = $json['reply_total']; + + if ($json['replies']) { + $results = $json['replies']; + + foreach ($results as $result) { + $data['replies'][] = array( + 'extension_comment_id' => $result['extension_comment_id'], + 'member' => $result['member'], + 'image' => $result['image'], + 'comment' => $result['comment'], + 'date_added' => $result['date_added'] + ); + } + } + + $data['refresh'] = $this->url->link('marketplace/marketplace/reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . $page); + + if (($page * 5) < $reply_total) { + $data['next'] = $this->url->link('marketplace/marketplace/reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . ($page + 1)); + } else { + $data['next'] = ''; + } + + $this->response->setOutput($this->load->view('marketplace/marketplace_reply', $data)); + } +} diff --git a/public/admin/controller/marketplace/modification.php b/public/admin/controller/marketplace/modification.php new file mode 100644 index 0000000..f094fc1 --- /dev/null +++ b/public/admin/controller/marketplace/modification.php @@ -0,0 +1,777 @@ +<?php +/** + * Modifcation XML Documentation can be found here: + * + * https://github.com/opencart/opencart/wiki/Modification-System + */ +class ControllerMarketplaceModification extends Controller { + private $error = array(); + + public function index() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + $this->getList(); + } + + public function delete() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if (isset($this->request->post['selected']) && $this->validate()) { + foreach ($this->request->post['selected'] as $modification_id) { + $this->model_setting_modification->deleteModification($modification_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function refresh($data = array()) { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if ($this->validate()) { + // Just before files are deleted, if config settings say maintenance mode is off then turn it on + $maintenance = $this->config->get('config_maintenance'); + + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSettingValue('config', 'config_maintenance', true); + + //Log + $log = array(); + + // Clear all modification files + $files = array(); + + // Make path into an array + $path = array(DIR_MODIFICATION . '*'); + + // While the path array is still populated keep looping through + while (count($path) != 0) { + $next = array_shift($path); + + foreach (glob($next) as $file) { + // If directory add to path array + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + // Add the file to the files to be deleted array + $files[] = $file; + } + } + + // Reverse sort the file array + rsort($files); + + // Clear all modification files + foreach ($files as $file) { + if ($file != DIR_MODIFICATION . 'index.html') { + // If file just delete + if (is_file($file)) { + unlink($file); + + // If directory use the remove directory function + } elseif (is_dir($file)) { + rmdir($file); + } + } + } + + // Begin + $xml = array(); + + // Load the default modification XML + $xml[] = file_get_contents(DIR_SYSTEM . 'modification.xml'); + + // This is purly for developers so they can run mods directly and have them run without upload after each change. + $files = glob(DIR_SYSTEM . '*.ocmod.xml'); + + if ($files) { + foreach ($files as $file) { + $xml[] = file_get_contents($file); + } + } + + // Get the default modification file + $results = $this->model_setting_modification->getModifications(); + + foreach ($results as $result) { + if ($result['status']) { + $xml[] = $result['xml']; + } + } + + $modification = array(); + + foreach ($xml as $xml) { + if (empty($xml)){ + continue; + } + + $dom = new DOMDocument('1.0', 'UTF-8'); + $dom->preserveWhiteSpace = false; + $dom->loadXml($xml); + + // Log + $log[] = 'MOD: ' . $dom->getElementsByTagName('name')->item(0)->textContent; + + // Wipe the past modification store in the backup array + $recovery = array(); + + // Set the a recovery of the modification code in case we need to use it if an abort attribute is used. + if (isset($modification)) { + $recovery = $modification; + } + + $files = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('file'); + + foreach ($files as $file) { + $operations = $file->getElementsByTagName('operation'); + + $files = explode('|', $file->getAttribute('path')); + + foreach ($files as $file) { + $path = ''; + + // Get the full path of the files that are going to be used for modification + if ((substr($file, 0, 7) == 'catalog')) { + $path = DIR_CATALOG . substr($file, 8); + } + + if ((substr($file, 0, 5) == 'admin')) { + $path = DIR_APPLICATION . substr($file, 6); + } + + if ((substr($file, 0, 6) == 'system')) { + $path = DIR_SYSTEM . substr($file, 7); + } + + if ($path) { + $files = glob($path, GLOB_BRACE); + + if ($files) { + foreach ($files as $file) { + // Get the key to be used for the modification cache filename. + if (substr($file, 0, strlen(DIR_CATALOG)) == DIR_CATALOG) { + $key = 'catalog/' . substr($file, strlen(DIR_CATALOG)); + } + + if (substr($file, 0, strlen(DIR_APPLICATION)) == DIR_APPLICATION) { + $key = 'admin/' . substr($file, strlen(DIR_APPLICATION)); + } + + if (substr($file, 0, strlen(DIR_SYSTEM)) == DIR_SYSTEM) { + $key = 'system/' . substr($file, strlen(DIR_SYSTEM)); + } + + // If file contents is not already in the modification array we need to load it. + if (!isset($modification[$key])) { + $content = file_get_contents($file); + + $modification[$key] = preg_replace('~\r?\n~', "\n", $content); + $original[$key] = preg_replace('~\r?\n~', "\n", $content); + + // Log + $log[] = PHP_EOL . 'FILE: ' . $key; + } + + foreach ($operations as $operation) { + $error = $operation->getAttribute('error'); + + // Ignoreif + $ignoreif = $operation->getElementsByTagName('ignoreif')->item(0); + + if ($ignoreif) { + if ($ignoreif->getAttribute('regex') != 'true') { + if (strpos($modification[$key], $ignoreif->textContent) !== false) { + continue; + } + } else { + if (preg_match($ignoreif->textContent, $modification[$key])) { + continue; + } + } + } + + $status = false; + + // Search and replace + if ($operation->getElementsByTagName('search')->item(0)->getAttribute('regex') != 'true') { + // Search + $search = $operation->getElementsByTagName('search')->item(0)->textContent; + $trim = $operation->getElementsByTagName('search')->item(0)->getAttribute('trim'); + $index = $operation->getElementsByTagName('search')->item(0)->getAttribute('index'); + + // Trim line if no trim attribute is set or is set to true. + if (!$trim || $trim == 'true') { + $search = trim($search); + } + + // Add + $add = $operation->getElementsByTagName('add')->item(0)->textContent; + $trim = $operation->getElementsByTagName('add')->item(0)->getAttribute('trim'); + $position = $operation->getElementsByTagName('add')->item(0)->getAttribute('position'); + $offset = $operation->getElementsByTagName('add')->item(0)->getAttribute('offset'); + + if ($offset == '') { + $offset = 0; + } + + // Trim line if is set to true. + if ($trim == 'true') { + $add = trim($add); + } + + // Log + $log[] = 'CODE: ' . $search; + + // Check if using indexes + if ($index !== '') { + $indexes = explode(',', $index); + } else { + $indexes = array(); + } + + // Get all the matches + $i = 0; + + $lines = explode("\n", $modification[$key]); + + for ($line_id = 0; $line_id < count($lines); $line_id++) { + $line = $lines[$line_id]; + + // Status + $match = false; + + // Check to see if the line matches the search code. + if (stripos($line, $search) !== false) { + // If indexes are not used then just set the found status to true. + if (!$indexes) { + $match = true; + } elseif (in_array($i, $indexes)) { + $match = true; + } + + $i++; + } + + // Now for replacing or adding to the matched elements + if ($match) { + switch ($position) { + default: + case 'replace': + $new_lines = explode("\n", $add); + + if ($offset < 0) { + array_splice($lines, $line_id + $offset, abs($offset) + 1, array(str_replace($search, $add, $line))); + + $line_id -= $offset; + } else { + array_splice($lines, $line_id, $offset + 1, array(str_replace($search, $add, $line))); + } + break; + case 'before': + $new_lines = explode("\n", $add); + + array_splice($lines, $line_id - $offset, 0, $new_lines); + + $line_id += count($new_lines); + break; + case 'after': + $new_lines = explode("\n", $add); + + array_splice($lines, ($line_id + 1) + $offset, 0, $new_lines); + + $line_id += count($new_lines); + break; + } + + // Log + $log[] = 'LINE: ' . $line_id; + + $status = true; + } + } + + $modification[$key] = implode("\n", $lines); + } else { + $search = trim($operation->getElementsByTagName('search')->item(0)->textContent); + $limit = $operation->getElementsByTagName('search')->item(0)->getAttribute('limit'); + $replace = trim($operation->getElementsByTagName('add')->item(0)->textContent); + + // Limit + if (!$limit) { + $limit = -1; + } + + // Log + $match = array(); + + preg_match_all($search, $modification[$key], $match, PREG_OFFSET_CAPTURE); + + // Remove part of the the result if a limit is set. + if ($limit > 0) { + $match[0] = array_slice($match[0], 0, $limit); + } + + if ($match[0]) { + $log[] = 'REGEX: ' . $search; + + for ($i = 0; $i < count($match[0]); $i++) { + $log[] = 'LINE: ' . (substr_count(substr($modification[$key], 0, $match[0][$i][1]), "\n") + 1); + } + + $status = true; + } + + // Make the modification + $modification[$key] = preg_replace($search, $replace, $modification[$key], $limit); + } + + if (!$status) { + // Abort applying this modification completely. + if ($error == 'abort') { + $modification = $recovery; + // Log + $log[] = 'NOT FOUND - ABORTING!'; + break 5; + } + // Skip current operation or break + elseif ($error == 'skip') { + // Log + $log[] = 'NOT FOUND - OPERATION SKIPPED!'; + continue; + } + // Break current operations + else { + // Log + $log[] = 'NOT FOUND - OPERATIONS ABORTED!'; + break; + } + } + } + } + } + } + } + } + + // Log + $log[] = '----------------------------------------------------------------'; + } + + // Log + $ocmod = new Log('ocmod.log'); + $ocmod->write(implode("\n", $log)); + + // Write all modification files + foreach ($modification as $key => $value) { + // Only create a file if there are changes + if ($original[$key] != $value) { + $path = ''; + + $directories = explode('/', dirname($key)); + + foreach ($directories as $directory) { + $path = $path . '/' . $directory; + + if (!is_dir(DIR_MODIFICATION . $path)) { + @mkdir(DIR_MODIFICATION . $path, 0777); + } + } + + $handle = fopen(DIR_MODIFICATION . $key, 'w'); + + fwrite($handle, $value); + + fclose($handle); + } + } + + // Maintance mode back to original settings + $this->model_setting_setting->editSettingValue('config', 'config_maintenance', $maintenance); + + // Do not return success message if refresh() was called with $data + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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(!empty($data['redirect']) ? $data['redirect'] : 'marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function clear() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if ($this->validate()) { + $files = array(); + + // Make path into an array + $path = array(DIR_MODIFICATION . '*'); + + // While the path array is still populated keep looping through + while (count($path) != 0) { + $next = array_shift($path); + + foreach (glob($next) as $file) { + // If directory add to path array + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + // Add the file to the files to be deleted array + $files[] = $file; + } + } + + // Reverse sort the file array + rsort($files); + + // Clear all modification files + foreach ($files as $file) { + if ($file != DIR_MODIFICATION . 'index.html') { + // If file just delete + if (is_file($file)) { + unlink($file); + + // If directory use the remove directory function + } elseif (is_dir($file)) { + rmdir($file); + } + } + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function enable() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if (isset($this->request->get['modification_id']) && $this->validate()) { + $this->model_setting_modification->enableModification($this->request->get['modification_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function disable() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if (isset($this->request->get['modification_id']) && $this->validate()) { + $this->model_setting_modification->disableModification($this->request->get['modification_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function clearlog() { + $this->load->language('marketplace/modification'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/modification'); + + if ($this->validate()) { + $handle = fopen(DIR_LOGS . 'ocmod.log', 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['refresh'] = $this->url->link('marketplace/modification/refresh', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['clear'] = $this->url->link('marketplace/modification/clear', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('marketplace/modification/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['modifications'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $modification_total = $this->model_setting_modification->getTotalModifications(); + + $results = $this->model_setting_modification->getModifications($filter_data); + + foreach ($results as $result) { + $data['modifications'][] = array( + 'modification_id' => $result['modification_id'], + 'name' => $result['name'], + 'author' => $result['author'], + 'version' => $result['version'], + 'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'link' => $result['link'], + 'enable' => $this->url->link('marketplace/modification/enable', 'user_token=' . $this->session->data['user_token'] . '&modification_id=' . $result['modification_id'], true), + 'disable' => $this->url->link('marketplace/modification/disable', 'user_token=' . $this->session->data['user_token'] . '&modification_id=' . $result['modification_id'], true), + 'enabled' => $result['status'] + ); + } + + $data['user_token'] = $this->session->data['user_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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_author'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=author' . $url, true); + $data['sort_version'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=version' . $url, true); + $data['sort_status'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url, true); + + $url = ''; + + 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 = $modification_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($modification_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($modification_total - $this->config->get('config_limit_admin'))) ? $modification_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $modification_total, ceil($modification_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + // Log + $file = DIR_LOGS . 'ocmod.log'; + + if (file_exists($file)) { + $data['log'] = htmlentities(file_get_contents($file, FILE_USE_INCLUDE_PATH, null)); + } else { + $data['log'] = ''; + } + + $data['clear_log'] = $this->url->link('marketplace/modification/clearlog', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/modification', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'marketplace/modification')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/marketplace/openbay.php b/public/admin/controller/marketplace/openbay.php new file mode 100644 index 0000000..5196c74 --- /dev/null +++ b/public/admin/controller/marketplace/openbay.php @@ -0,0 +1,2303 @@ +<?php +class ControllerMarketplaceOpenbay extends Controller { + private $error = array(); + + public function install() { + $this->load->language('marketplace/openbay'); + + $this->load->model('setting/extension'); + + if (!$this->user->hasPermission('modify', 'marketplace/openbay')) { + $this->session->data['error'] = $this->language->get('error_permission'); + + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->model_setting_extension->install('openbay', $this->request->get['extension']); + + $this->session->data['success'] = $this->language->get('text_install_success'); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/' . $this->request->get['extension']); + + require_once(DIR_APPLICATION . 'controller/extension/openbay/' . $this->request->get['extension'] . '.php'); + + $class = 'ControllerExtensionOpenbay' . str_replace('_', '', $this->request->get['extension']); + $class = new $class($this->registry); + + if (method_exists($class, 'install')) { + $class->install(); + } + + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function uninstall() { + $this->load->language('marketplace/openbay'); + + $this->load->model('setting/extension'); + + if (!$this->user->hasPermission('modify', 'marketplace/openbay')) { + $this->session->data['error'] = $this->language->get('error_permission'); + + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->session->data['success'] = $this->language->get('text_uninstall_success'); + + require_once(DIR_APPLICATION . 'controller/extension/openbay/' . $this->request->get['extension'] . '.php'); + + $this->load->model('setting/extension'); + $this->load->model('setting/setting'); + + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + + $class = 'ControllerExtensionOpenbay' . str_replace('_', '', $this->request->get['extension']); + $class = new $class($this->registry); + + if (method_exists($class, 'uninstall')) { + $class->uninstall(); + } + + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function index() { + $this->load->language('marketplace/openbay'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/openbay'); + $this->load->model('setting/extension'); + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/version'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['manage_link'] = $this->url->link('marketplace/openbay/manage', 'user_token=' . $this->session->data['user_token'], true); + $data['product_link'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['order_link'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true); + + $data['success'] = ''; + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['error'] = $this->model_extension_openbay_openbay->requirementTest(); + + if (isset($this->session->data['error'])) { + $data['error'][] = $this->session->data['error']; + unset($this->session->data['error']); + } + + $extensions = $this->model_setting_extension->getInstalled('openbay'); + + foreach ($extensions as $key => $value) { + if (!file_exists(DIR_APPLICATION . 'controller/extension/openbay/' . $value . '.php')) { + $this->model_setting_extension->uninstall('openbay', $value); + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + $markets = array('ebay', 'etsy', 'amazon', 'amazonus', 'fba'); + + foreach ($markets as $market) { + $extension = basename($market, '.php'); + + $this->load->language('extension/openbay/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'edit' => $this->url->link('extension/openbay/' . $extension . '', 'user_token=' . $this->session->data['user_token'], true), + 'status' => ($this->config->get('openbay_' . $extension . '_status') || $this->config->get($extension . '_status')) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('marketplace/openbay/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('marketplace/openbay/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'code' => $extension + ); + } + + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + + if (isset($settings['feed_openbaypro_version'])) { + $data['feed_openbaypro_version'] = $settings['feed_openbaypro_version']; + } else { + $data['feed_openbaypro_version'] = $this->model_extension_openbay_version->version(); + $settings['feed_openbaypro_version'] = $this->model_extension_openbay_version->version(); + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('marketplace/openbay', $data)); + } + + public function manage() { + $this->load->language('marketplace/openbay'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('text_manage')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay/manage', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_manage'), + ); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + $this->model_setting_setting->editSetting('feed_openbaypro', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (isset($this->request->post['feed_openbaypro_version'])) { + $data['feed_openbaypro_version'] = $this->request->post['feed_openbaypro_version']; + } else { + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + + if (isset($settings['feed_openbaypro_version'])) { + $data['feed_openbaypro_version'] = $settings['feed_openbaypro_version']; + } else { + $this->load->model('extension/openbay/version'); + $settings['feed_openbaypro_version'] = $this->model_extension_openbay_version->version(); + $data['feed_openbaypro_version'] = $this->model_extension_openbay_version->version(); + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + } + } + + if (isset($this->request->post['feed_openbaypro_language'])) { + $data['feed_openbaypro_language'] = $this->request->post['feed_openbaypro_language']; + } else { + $data['feed_openbaypro_language'] = $this->config->get('feed_openbaypro_language'); + } + + $data['api_languages'] = array( + 'en_GB' => 'English', + 'de_DE' => 'German', + 'es_ES' => 'Spanish', + 'fr_FR' => 'French', + 'it_IT' => 'Italian', + 'nl_NL' => 'Dutch', + 'zh_HK' => 'Simplified Chinese' + ); + + $data['text_version'] = $this->config->get('feed_openbaypro_version'); + + $data['action'] = $this->url->link('marketplace/openbay/manage', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/openbay_manage', $data)); + } + + public function update() { + $this->load->model('extension/openbay/openbay'); + $this->load->language('marketplace/openbay'); + + if (!isset($this->request->get['stage'])) { + $stage = 'check_server'; + } else { + $stage = $this->request->get['stage']; + } + + if (!isset($this->request->get['beta']) || $this->request->get['beta'] == 0) { + $beta = 0; + } else { + $beta = 1; + } + + switch ($stage) { + case 'check_server': // step 1 + $response = $this->model_extension_openbay_openbay->updateTest(); + + sleep(1); + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + case 'check_version': // step 2 + $response = $this->model_extension_openbay_openbay->updateCheckVersion($beta); + + sleep(1); + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + + break; + case 'download': // step 3 + $response = $this->model_extension_openbay_openbay->updateDownload($beta); + + sleep(1); + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + case 'extract': // step 4 + $response = $this->model_extension_openbay_openbay->updateExtract(); + + sleep(1); + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + case 'remove': // step 5 - remove any files no longer needed + $response = $this->model_extension_openbay_openbay->updateRemove($beta); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + case 'run_patch': // step 6 - run any db updates or other patch files + $this->model_extension_openbay_openbay->patch(); + + $this->load->model('extension/openbay/ebay'); + $this->model_extension_openbay_ebay->patch(); + + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->patch(); + + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->patch(); + + $this->load->model('extension/openbay/etsy'); + $this->model_extension_openbay_etsy->patch(); + + $response = array('error' => 0, 'response' => '', 'percent_complete' => 90, 'status_message' => 'Running patch files'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + case 'update_version': // step 7 - update the version number + $this->load->model('setting/setting'); + + $response = $this->model_extension_openbay_openbay->updateUpdateVersion($beta); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + break; + default; + } + } + + public function patch() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/amazon'); + $this->load->model('extension/openbay/amazonus'); + $this->load->model('extension/openbay/etsy'); + $this->load->model('setting/extension'); + $this->load->model('setting/setting'); + $this->load->model('user/user_group'); + $this->load->model('extension/openbay/version'); + + $this->model_extension_openbay_openbay->patch(); + $this->model_extension_openbay_ebay->patch(); + $this->model_extension_openbay_amazon->patch(); + $this->model_extension_openbay_amazonus->patch(); + $this->model_extension_openbay_etsy->patch(); + + $openbay = $this->model_setting_setting->getSetting('feed_openbaypro'); + $openbay['feed_openbaypro_version'] = (int)$this->model_extension_openbay_version->version(); + $this->model_setting_setting->editSetting('feed_openbaypro', $openbay); + + $installed_modules = $this->model_setting_extension->getInstalled('feed'); + + if (!in_array('openbay', $installed_modules)) { + $this->model_setting_extension->install('feed', 'openbaypro'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'marketplace/openbay'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'marketplace/openbay'); + } + + sleep(1); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function notifications() { + $this->load->model('extension/openbay/openbay'); + + $json = $this->model_extension_openbay_openbay->getNotifications(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function version() { + $this->load->model('extension/openbay/openbay'); + + $json = $this->model_extension_openbay_openbay->version(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function faq() { + $this->load->language('marketplace/openbay'); + + $this->load->model('extension/openbay/openbay'); + + $data = $this->model_extension_openbay_openbay->faqGet($this->request->get['qry_route']); + + $data['button_faq'] = $this->language->get('button_faq'); + $data['button_close'] = $this->language->get('button_close'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($data)); + } + + public function faqDismiss() { + $this->load->model('extension/openbay/openbay'); + + $this->model_extension_openbay_openbay->faqDismiss($this->request->get['qry_route']); + + $json = array(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function faqClear() { + $this->load->model('extension/openbay/openbay'); + $this->model_extension_openbay_openbay->faqClear(); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getOrderInfo() { + $this->load->language('marketplace/openbay'); + + $data = $this->language->all(); + + if ($this->config->get('ebay_status') == 1) { + if ($this->openbay->ebay->getOrder($this->request->get['order_id']) !== false) { + if ($this->config->get('ebay_status_shipped_id') == $this->request->get['status_id']) { + $data['carriers'] = $this->openbay->ebay->getCarriers(); + $data['order_info'] = $this->openbay->ebay->getOrder($this->request->get['order_id']); + $this->response->setOutput($this->load->view('extension/openbay/ebay_ajax_shippinginfo', $data)); + } + } + } + + if ($this->config->get('openbay_amazon_status') == 1) { + $data['order_info'] = $this->openbay->amazon->getOrder($this->request->get['order_id']); + + if ($data['order_info']) { + if ($this->request->get['status_id'] == $this->config->get('openbay_amazon_order_status_shipped')) { + $data['couriers'] = $this->openbay->amazon->getCarriers(); + $data['courier_default'] = $this->config->get('openbay_amazon_default_carrier'); + $this->response->setOutput($this->load->view('extension/openbay/amazon_ajax_shippinginfo', $data)); + } + } + } + + if ($this->config->get('openbay_amazonus_status') == 1) { + $data['order_info'] = $this->openbay->amazonus->getOrder($this->request->get['order_id']); + + if ($data['order_info']) { + if ($this->request->get['status_id'] == $this->config->get('openbay_amazonus_order_status_shipped')) { + $data['couriers'] = $this->openbay->amazonus->getCarriers(); + $data['courier_default'] = $this->config->get('openbay_amazonus_default_carrier'); + $this->response->setOutput($this->load->view('extension/openbay/amazonus_ajax_shippinginfo', $data)); + } + } + } + + if ($this->config->get('etsy_status') == 1) { + $data['order_info'] = $this->openbay->etsy->orderFind($this->request->get['order_id']); + + if ($data['order_info']) { + if ($this->request->get['status_id'] == $this->config->get('etsy_order_status_shipped')) { + + } + } + } + } + + public function addOrderInfo() { + if ($this->config->get('ebay_status') == 1 && $this->openbay->ebay->getOrder($this->request->get['order_id']) !== false) { + if ($this->config->get('ebay_status_shipped_id') == $this->request->get['status_id']) { + $this->openbay->ebay->orderStatusListen($this->request->get['order_id'], $this->request->get['status_id'], array('tracking_no' => $this->request->post['tracking_no'], 'carrier_id' => $this->request->post['carrier_id'])); + } else { + $this->openbay->ebay->orderStatusListen($this->request->get['order_id'], $this->request->get['status_id']); + } + } + + if ($this->config->get('openbay_amazon_status') == 1 && $this->openbay->amazon->getOrder($this->request->get['order_id']) !== false) { + if ($this->config->get('openbay_amazon_order_status_shipped') == $this->request->get['status_id']) { + if (!empty($this->request->post['courier_other'])) { + $this->openbay->amazon->updateOrder($this->request->get['order_id'], 'shipped', $this->request->post['courier_other'], false, $this->request->post['tracking_no']); + } else { + $this->openbay->amazon->updateOrder($this->request->get['order_id'], 'shipped', $this->request->post['courier_id'], true, $this->request->post['tracking_no']); + } + } + + if ($this->config->get('openbay_amazon_order_status_canceled') == $this->request->get['status_id']) { + $this->openbay->amazon->updateOrder($this->request->get['order_id'], 'canceled'); + } + } + + if ($this->config->get('openbay_amazonus_status') == 1 && $this->openbay->amazonus->getOrder($this->request->get['order_id']) !== false) { + if ($this->config->get('openbay_amazonus_order_status_shipped') == $this->request->get['status_id']) { + if (!empty($this->request->post['courier_other'])) { + $this->openbay->amazonus->updateOrder($this->request->get['order_id'], 'shipped', $this->request->post['courier_other'], false, $this->request->post['tracking_no']); + } else { + $this->openbay->amazonus->updateOrder($this->request->get['order_id'], 'shipped', $this->request->post['courier_id'], true, $this->request->post['tracking_no']); + } + } + if ($this->config->get('openbay_amazonus_order_status_canceled') == $this->request->get['status_id']) { + $this->openbay->amazonus->updateOrder($this->request->get['order_id'], 'canceled'); + } + } + + if ($this->config->get('etsy_status') == 1) { + $linked_order = $this->openbay->etsy->orderFind($this->request->get['order_id']); + + if ($linked_order != false) { + if ($this->config->get('etsy_order_status_paid') == $this->request->get['status_id']) { + $response = $this->openbay->etsy->orderUpdatePaid($linked_order['receipt_id'], "true"); + } + + if ($this->config->get('etsy_order_status_shipped') == $this->request->get['status_id']) { + $response = $this->openbay->etsy->orderUpdateShipped($linked_order['receipt_id'], "true"); + } + } + } + } + + public function updateOrderInfo() { + $json = array(); + + /** + * response options: + * json['error'] = status DID NOT update + * json['success'] = status UPDATED, just set value to true. + * json['info'] = status UPDATED but messages or information were returned + */ + + $order_id = (int)$this->request->get['order_id']; + $status_id = (int)$this->request->get['status_id']; + $web_order = 1; + + if ($this->config->get('ebay_status') == 1 && $this->openbay->ebay->getOrder($order_id) !== false) { + $web_order = 0; + + if ($this->config->get('ebay_status_shipped_id') == $status_id) { + $response = $this->openbay->ebay->orderStatusListen($order_id, $status_id, array('tracking_no' => (string)$this->request->post['tracking_no'], 'carrier_id' => (string)$this->request->post['carrier_id'])); + } else { + $response = $this->openbay->ebay->orderStatusListen($order_id, $status_id); + } + } + + if ($this->config->get('openbay_amazon_status') == 1 && $this->openbay->amazon->getOrder($order_id) !== false) { + $web_order = 0; + + if ($this->config->get('openbay_amazon_order_status_shipped') == $status_id) { + if (!empty($this->request->post['courier_other'])) { + $response = $this->openbay->amazon->updateOrder($order_id, 'shipped', (string)$this->request->post['courier_other'], false, (string)$this->request->post['tracking_no']); + } else { + $response = $this->openbay->amazon->updateOrder($order_id, 'shipped', (string)$this->request->post['courier_id'], true, (string)$this->request->post['tracking_no']); + } + } + + if ($this->config->get('openbay_amazon_order_status_canceled') == $status_id) { + $response = $this->openbay->amazon->updateOrder($order_id, 'canceled'); + } + } + + if ($this->config->get('openbay_amazonus_status') == 1 && $this->openbay->amazonus->getOrder($order_id) !== false) { + $web_order = 0; + + if ($this->config->get('openbay_amazonus_order_status_shipped') == $status_id) { + if (!empty($this->request->post['courier_other'])) { + $response = $this->openbay->amazonus->updateOrder($order_id, 'shipped', (string)$this->request->post['courier_other'], false, (string)$this->request->post['tracking_no']); + } else { + $response = $this->openbay->amazonus->updateOrder($order_id, 'shipped', (string)$this->request->post['courier_id'], true, (string)$this->request->post['tracking_no']); + } + } + if ($this->config->get('openbay_amazonus_order_status_canceled') == $status_id) { + $response = $this->openbay->amazonus->updateOrder($order_id, 'canceled'); + } + } + + if ($this->config->get('etsy_status') == 1) { + $linked_order = $this->openbay->etsy->orderFind($order_id); + + if ($linked_order != false) { + $web_order = 0; + + if ($this->config->get('etsy_order_status_paid') == $status_id) { + $response = $this->openbay->etsy->orderUpdatePaid($linked_order['receipt_id'], "true"); + } + + if ($this->config->get('etsy_order_status_shipped') == $status_id) { + $response = $this->openbay->etsy->orderUpdateShipped($linked_order['receipt_id'], "true"); + } + } + } + + if ($web_order == 1) { + // no need to check a web order here, skip + $json['success'] = true; + } else { + + + + // @todo + // use the response from marketplace to determine success/fail + $json['success'] = true; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function orderList() { + $this->load->language('sale/order'); + $this->load->language('extension/openbay/openbay_order'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/order'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js'); + $this->document->addStyle('view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css'); + + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + 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 = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['filter_channel'])) { + $filter_channel = $this->request->get['filter_channel']; + } else { + $filter_channel = ''; + } + + 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=' . $this->request->get['filter_customer']; + } + + 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_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_channel'])) { + $url .= '&filter_channel=' . $this->request->get['filter_channel']; + } + + 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( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay/manage', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $data['orders'] = array(); + + $filter = array( + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_order_status_id' => $filter_order_status_id, + 'filter_date_added' => $filter_date_added, + 'filter_channel' => $filter_channel, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_openbay_order->getTotalOrders($filter); + $results = $this->model_extension_openbay_order->getOrders($filter); + + foreach ($results as $result) { + $channel = $this->language->get('text_' . $result['channel']); + + if ($result['channel'] == "ebay") { + $market_order_ref = $result['ebay_order_ref']; + } elseif ($result['channel'] == "amazon") { + $market_order_ref = $result['amazon_order_ref']; + } elseif ($result['channel'] == "amazonus") { + $market_order_ref = $result['amazonus_order_ref']; + } elseif ($result['channel'] == "etsy") { + $market_order_ref = $result['etsy_order_ref']; + } else { + $market_order_ref = "-"; + } + + $data['orders'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'status' => $result['status'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'selected' => isset($this->request->post['selected']) && in_array($result['order_id'], $this->request->post['selected']), + 'view' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true), + 'channel' => $channel, + 'market_order_ref' => $market_order_ref, + ); + } + + $data['channels'] = array(); + + $data['channels'][] = array( + 'module' => 'web', + 'title' => $this->language->get('text_web'), + ); + + if ($this->config->get('ebay_status')) { + $data['channels'][] = array( + 'module' => 'ebay', + 'title' => $this->language->get('text_ebay'), + ); + } + + if ($this->config->get('openbay_amazon_status')) { + $data['channels'][] = array( + 'module' => 'amazon', + 'title' => $this->language->get('text_amazon'), + ); + } + + if ($this->config->get('openbay_amazonus_status')) { + $data['channels'][] = array( + 'module' => 'amazonus', + 'title' => $this->language->get('text_amazonus'), + ); + } + + if ($this->config->get('etsy_status')) { + $data['channels'][] = array( + 'module' => 'etsy', + 'title' => $this->language->get('text_etsy'), + ); + } + + $data['heading_title'] = $this->language->get('heading_title'); + $data['text_no_results'] = $this->language->get('text_no_results'); + $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_date_added'] = $this->language->get('column_date_added'); + $data['column_action'] = $this->language->get('column_action'); + $data['button_filter'] = $this->language->get('button_filter'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + if (!is_array($this->session->data['error'])) { + $this->session->data['error'] = array($this->session->data['error']); + } + + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $data['error_orders'] = ''; + + if (isset($this->session->data['error_orders'])) { + if (is_array($this->session->data['error_orders'])) { + $data['error_orders'] = $this->session->data['error_orders']; + } + + unset($this->session->data['error_orders']); + } + + $data['success_orders'] = ''; + + if (isset($this->session->data['success_orders'])) { + if (is_array($this->session->data['success_orders'])) { + $data['success_orders'] = $this->session->data['success_orders']; + } + + unset($this->session->data['success_orders']); + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['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=' . $this->request->get['filter_customer']; + } + + 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_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_channel'])) { + $url .= '&filter_channel=' . $this->request->get['filter_channel']; + } + + 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('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . '&sort=o.order_id' . $url, true); + $data['sort_customer'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_status'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_added' . $url, true); + $data['sort_channel'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . '&sort=channel' . $url, true); + $data['link_update'] = $this->url->link('marketplace/openbay/orderlistupdate', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['cancel'] = $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true); + + $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=' . $this->request->get['filter_customer']; + } + + 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_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_channel'])) { + $url .= '&filter_channel=' . $this->request->get['filter_channel']; + } + + 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->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $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_date_added'] = $filter_date_added; + $data['filter_channel'] = $filter_channel; + + $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['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/openbay_orderlist', $data)); + } + + public function orderListUpdate() { + if (!isset($this->request->post['selected']) || empty($this->request->post['selected'])) { + $this->load->language('extension/openbay/openbay_order'); + $data = $this->language->all(); + + $this->session->data['error'] = $data['text_no_orders']; + $this->response->redirect($this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->load->language('sale/order'); + $this->load->language('extension/openbay/openbay_order'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $this->load->model('extension/openbay/order'); + + + $data['market_options'] = array(); + + if ($this->config->get('ebay_status') == 1) { + $data['market_options']['ebay']['carriers'] = $this->openbay->ebay->getCarriers(); + } + + if ($this->config->get('openbay_amazon_status') == 1) { + $data['market_options']['amazon']['carriers'] = $this->openbay->amazon->getCarriers(); + $data['market_options']['amazon']['default_carrier'] = $this->config->get('openbay_amazon_default_carrier'); + } + + if ($this->config->get('openbay_amazonus_status') == 1) { + $data['market_options']['amazonus']['carriers'] = $this->openbay->amazonus->getCarriers(); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['status_mapped'] = array(); + + foreach($data['order_statuses'] as $status) { + $data['status_mapped'][$status['order_status_id']] = $status['name']; + } + + $orders = array(); + + foreach($this->request->post['selected'] as $order_id) { + $order = $this->model_extension_openbay_order->getOrder($order_id); + + if ($order['order_status_id'] != $this->request->post['change_order_status_id']) { + if ($order['channel'] == "ebay") { + $market_order_ref = $order['ebay_order_ref']; + } elseif ($order['channel'] == "amazon") { + $market_order_ref = $order['amazon_order_ref']; + } elseif ($order['channel'] == "amazonus") { + $market_order_ref = $order['amazonus_order_ref']; + } elseif ($order['channel'] == "etsy") { + $market_order_ref = $order['etsy_order_ref']; + } else { + $market_order_ref = "-"; + } + + $order['channel'] = $this->language->get('text_' . $order['channel']); + $order['view_order_link'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$order_id, true); + $order['market_order_ref'] = $market_order_ref; + $orders[] = $order; + } + } + + if (empty($orders)) { + $this->session->data['error'] = $data['text_no_orders']; + $this->response->redirect($this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['orders'] = $orders; + } + + $data['order_count'] = count($data['orders']); + + $data['change_order_status_id'] = $this->request->post['change_order_status_id']; + $data['ebay_status_shipped_id'] = $this->config->get('ebay_status_shipped_id'); + $data['openbay_amazon_order_status_shipped'] = $this->config->get('openbay_amazon_order_status_shipped'); + $data['openbay_amazonus_order_status_shipped'] = $this->config->get('openbay_amazonus_order_status_shipped'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $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_channel'])) { + $url .= '&filter_channel=' . $this->request->get['filter_channel']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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']; + } + + // API login + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + + // @todo if cannot get token then redirect and show error + + + + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['link_complete'] = $this->url->link('marketplace/openbay/orderlistcomplete', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->response->setOutput($this->load->view('extension/openbay/openbay_orderlist_confirm', $data)); + } + } + + public function orderListComplete() { + $this->load->model('sale/order'); + $this->load->model('extension/openbay/openbay'); + $this->load->model('localisation/order_status'); + + $this->load->language('extension/openbay/openbay_order'); + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), "127.0.0.1"); + + $session->data['api_id'] = $api_info['api_id']; + + $api_token = $session->getId(); + } else { + $this->session->data['error'] = $this->language->get('error_fetch_api_id'); + $this->response->redirect($this->url->link('marketplace/openbay/orderList', 'user_token=' . $this->session->data['user_token'], true)); + } + + //Amazon EU + if ($this->config->get('openbay_amazon_status') == 1) { + $this->load->model('extension/openbay/amazon'); + + $orders = array(); + + foreach ($this->request->post['order_id'] as $order_id) { + if ($this->request->post['channel'][$order_id] == 'Amazon EU') { + if ($this->config->get('openbay_amazon_order_status_shipped') == $this->request->post['order_status_id']) { + if (isset($this->request->post['carrier_other'][$order_id]) && !empty($this->request->post['carrier_other'][$order_id])) { + $carrier_from_list = false; + $carrier = $this->request->post['carrier_other'][$order_id]; + } else { + $carrier_from_list = true; + $carrier = $this->request->post['carrier'][$order_id]; + } + + $orders[] = array( + 'order_id' => $order_id, + 'status' => 'shipped', + 'carrier' => $carrier, + 'carrier_from_list' => $carrier_from_list, + 'tracking' => $this->request->post['tracking'][$order_id], + ); + + $this->model_extension_openbay_amazon->updateAmazonOrderTracking($order_id, $carrier, $carrier_from_list, !empty($carrier) ? $this->request->post['tracking'][$order_id] : ''); + } + + if ($this->config->get('openbay_amazon_order_status_canceled') == $this->request->post['order_status_id']) { + $orders[] = array( + 'order_id' => $order_id, + 'status' => 'canceled', + ); + } + } + } + + if ($orders) { + $this->openbay->amazon->bulkUpdateOrders($orders); + } + } + + //Amazon US + if ($this->config->get('openbay_amazonus_status') == 1) { + $this->load->model('extension/openbay/amazonus'); + + $orders = array(); + + foreach ($this->request->post['order_id'] as $order_id) { + if ($this->request->post['channel'][$order_id] == 'Amazon US') { + if ($this->config->get('openbay_amazonus_order_status_shipped') == $this->request->post['order_status_id']) { + $carrier = ''; + + if (isset($this->request->post['carrier_other'][$order_id]) && !empty($this->request->post['carrier_other'][$order_id])) { + $carrier_from_list = false; + $carrier = $this->request->post['carrier_other'][$order_id]; + } else { + $carrier_from_list = true; + $carrier = $this->request->post['carrier'][$order_id]; + } + + $orders[] = array( + 'order_id' => $order_id, + 'status' => 'shipped', + 'carrier' => $carrier, + 'carrier_from_list' => $carrier_from_list, + 'tracking' => $this->request->post['tracking'][$order_id], + ); + + $this->model_extension_openbay_amazonus->updateAmazonusOrderTracking($order_id, $carrier, $carrier_from_list, !empty($carrier) ? $this->request->post['tracking'][$order_id] : ''); + } + + if ($this->config->get('openbay_amazonus_order_status_canceled') == $this->request->post['order_status_id']) { + $orders[] = array( + 'order_id' => $order_id, + 'status' => 'canceled', + ); + } + } + } + + if ($orders) { + $this->openbay->amazonus->bulkUpdateOrders($orders); + } + } + + $i = 0; + + foreach ($this->request->post['order_id'] as $order_id) { + if ($this->config->get('ebay_status') == 1 && $this->request->post['channel'][$order_id] == 'eBay') { + if ($this->config->get('ebay_status_shipped_id') == $this->request->post['order_status_id']) { + $this->openbay->ebay->orderStatusListen($order_id, $this->request->post['order_status_id'], array('tracking_no' => $this->request->post['tracking'][$order_id], 'carrier_id' => $this->request->post['carrier'][$order_id])); + } else { + $this->openbay->ebay->orderStatusListen($order_id, $this->request->post['order_status_id']); + } + } + + if ($this->config->get('etsy_status') == 1 && $this->request->post['channel'][$order_id] == 'Etsy') { + $linked_order = $this->openbay->etsy->orderFind($order_id); + + if ($linked_order != false) { + if ($this->config->get('etsy_order_status_paid') == $this->request->post['order_status_id']) { + $response = $this->openbay->etsy->orderUpdatePaid($linked_order['receipt_id'], "true"); + } + + if ($this->config->get('etsy_order_status_shipped') == $this->request->post['order_status_id']) { + $response = $this->openbay->etsy->orderUpdateShipped($linked_order['receipt_id'], "true"); + } + } + } + + $data = array( + 'notify' => $this->request->post['notify'][$order_id], + 'order_status_id' => $this->request->post['order_status_id'], + 'comment' => $this->request->post['comments'][$order_id], + 'override' => 1, + ); + + $add_history = $this->model_extension_openbay_openbay->addOrderHistory($order_id, $data, $api_token); + + if (isset($add_history['error'])) { + $this->session->data['error_orders'][] = array( + 'order_id' => $order_id, + 'error' => $add_history['error'] + ); + } + + if (isset($add_history['success'])) { + $this->session->data['success_orders'][] = array( + 'order_id' => $order_id, + 'success' => $add_history['success'] + ); + } + + $i++; + } + + $this->session->data['success'] = sprintf($this->language->get('text_confirmed'), $i); + + + $this->response->redirect($this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function items() { + $this->load->language('catalog/product'); + $this->load->language('extension/openbay/openbay_itemlist'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('catalog/product'); + $this->load->model('catalog/category'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/openbay'); + $this->load->model('tool/image'); + + if ($this->openbay->addonLoad('openstock')) { + $this->load->model('extension/module/openstock'); + $openstock_installed = true; + } else { + $openstock_installed = false; + } + + $data['category_list'] = $this->model_catalog_category->getCategories(array()); + $data['manufacturer_list'] = $this->model_catalog_manufacturer->getManufacturers(array()); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_model'])) { + $filter_model = $this->request->get['filter_model']; + } else { + $filter_model = ''; + } + + if (isset($this->request->get['filter_price'])) { + $filter_price = $this->request->get['filter_price']; + } else { + $filter_price = ''; + } + + if (isset($this->request->get['filter_price_to'])) { + $filter_price_to = $this->request->get['filter_price_to']; + } else { + $filter_price_to = ''; + } + + if (isset($this->request->get['filter_quantity'])) { + $filter_quantity = $this->request->get['filter_quantity']; + } else { + $filter_quantity = ''; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $filter_quantity_to = $this->request->get['filter_quantity_to']; + } else { + $filter_quantity_to = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['filter_sku'])) { + $filter_sku = $this->request->get['filter_sku']; + } else { + $filter_sku = ''; + } + + if (isset($this->request->get['filter_desc'])) { + $filter_desc = $this->request->get['filter_desc']; + } else { + $filter_desc = ''; + } + + if (isset($this->request->get['filter_category'])) { + $filter_category = $this->request->get['filter_category']; + } else { + $filter_category = ''; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $filter_manufacturer = $this->request->get['filter_manufacturer']; + } else { + $filter_manufacturer = ''; + } + + if (isset($this->request->get['filter_marketplace'])) { + $filter_marketplace = $this->request->get['filter_marketplace']; + } else { + $filter_marketplace = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'pd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['filter_marketplace'])) { + $url .= '&filter_marketplace=' . $this->request->get['filter_marketplace']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_openbay'), + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true), + ); + + if ($this->config->get('openbay_amazon_status')) { + $data['link_amazon_eu_bulk'] = $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['link_amazon_eu_bulk'] = ''; + } + + if ($this->config->get('openbay_amazonus_status')) { + $data['link_amazon_us_bulk'] = $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['link_amazon_us_bulk'] = ''; + } + + if ($this->config->get('ebay_status') == '1') { + $data['link_ebay_bulk'] = $this->url->link('extension/openbay/openbay/createBulk', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['link_ebay_bulk'] = ''; + } + + $data['products'] = array(); + + $filter_market_id = ''; + $filter_market_name = ''; + + $ebay_status = array( + 0 => 'ebay_inactive', + 1 => 'ebay_active', + ); + + if (in_array($filter_marketplace, $ebay_status)) { + $filter_market_name = 'ebay'; + $filter_market_id = array_search($filter_marketplace, $ebay_status); + } + + $amazon_status = array( + 0 => 'amazon_unlisted', + 1 => 'amazon_saved', + 2 => 'amazon_uploaded', + 3 => 'amazon_ok', + 4 => 'amazon_error', + 5 => 'amazon_linked', + 6 => 'amazon_not_linked', + ); + + if (in_array($filter_marketplace, $amazon_status)) { + $filter_market_name = 'amazon'; + $filter_market_id = array_search($filter_marketplace, $amazon_status); + } + + $amazonus_status = array( + 0 => 'amazonus_unlisted', + 1 => 'amazonus_saved', + 2 => 'amazonus_uploaded', + 3 => 'amazonus_ok', + 4 => 'amazonus_error', + 5 => 'amazonus_linked', + 6 => 'amazonus_not_linked', + ); + + if (in_array($filter_marketplace, $amazonus_status)) { + $filter_market_name = 'amazonus'; + $filter_market_id = array_search($filter_marketplace, $amazonus_status); + } + + $filter = array( + 'filter_name' => $filter_name, + 'filter_model' => $filter_model, + 'filter_price' => $filter_price, + 'filter_price_to' => $filter_price_to, + 'filter_quantity' => $filter_quantity, + 'filter_quantity_to' => $filter_quantity_to, + 'filter_status' => $filter_status, + 'filter_sku' => $filter_sku, + 'filter_desc' => $filter_desc, + 'filter_category' => $filter_category, + 'filter_manufacturer' => $filter_manufacturer, + 'filter_market_name' => $filter_market_name, + 'filter_market_id' => $filter_market_id, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + if ($this->config->get('ebay_status') != '1' && $filter['filter_market_name'] == 'ebay') { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + if ($this->config->get('openbay_amazon_status') != '1' && $filter['filter_market_name'] == 'amazon') { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + if ($this->config->get('openbay_amazonus_status') != '1' && $filter['filter_market_name'] == 'amazonus') { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + if ($this->config->get('etsy_status') != '1' && $filter['filter_market_name'] == 'etsy') { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $data['marketplace_statuses'] = array( + 'ebay' => $this->config->get('ebay_status'), + 'amazon' => $this->config->get('openbay_amazon_status'), + 'amazonus' => $this->config->get('openbay_amazonus_status'), + 'etsy' => $this->config->get('etsy_status'), + ); + + $product_total = $this->model_extension_openbay_openbay->getTotalProducts($filter); + + $results = $this->model_extension_openbay_openbay->getProducts($filter); + + foreach ($results as $result) { + $edit = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true); + + if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) { + $image = $this->model_tool_image->resize($result['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + $special = false; + + $product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']); + + foreach ($product_specials as $product_special) { + if (($product_special['date_start'] == '0000-00-00' || $product_special['date_start'] < date('Y-m-d')) && ($product_special['date_end'] == '0000-00-00' || $product_special['date_end'] > date('Y-m-d'))) { + $special = $product_special['price']; + + break; + } + } + + /** + * Button status key: + * 0 = Inactive / no link to market + * 1 = Active + * 2 = Error + * 3 = Pending + */ + + $markets = array(); + + if ($this->config->get('ebay_status') == '1') { + $this->load->model('extension/openbay/ebay'); + + $active_list = $this->model_extension_openbay_ebay->getLiveListingArray(); + + if (!array_key_exists($result['product_id'], $active_list)) { + $markets[] = array( + 'name' => $this->language->get('text_ebay'), + 'text' => $this->language->get('button_add'), + 'href' => $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 0 + ); + } else { + $markets[] = array( + 'name' => $this->language->get('text_ebay'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 1 + ); + } + } + + if ($this->config->get('openbay_amazon_status') == '1') { + $this->load->model('extension/openbay/amazon'); + $amazon_status = $this->model_extension_openbay_amazon->getProductStatus($result['product_id']); + + if ($amazon_status == 'processing') { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('text_processing'), + 'href' => '', + 'status' => 3 + ); + } else if ($amazon_status == 'linked' || $amazon_status == 'ok') { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url), + 'status' => 1 + ); + } else if ($amazon_status == 'saved') { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 4 + ); + } else if ($amazon_status == 'error_quick' || $amazon_status == 'error_advanced' || $amazon_status == 'error_few') { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('button_error_fix'), + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url), + 'status' => 2 + ); + } else { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('button_add'), + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url), + 'status' => 0 + ); + } + } + + if ($this->config->get('openbay_amazonus_status') == '1') { + $this->load->model('extension/openbay/amazonus'); + $amazonus_status = $this->model_extension_openbay_amazonus->getProductStatus($result['product_id']); + + if ($amazonus_status == 'processing') { + $markets[] = array( + 'name' => $this->language->get('text_amazonus'), + 'text' => $this->language->get('text_processing'), + 'href' => '', + 'status' => 3 + ); + } else if ($amazonus_status == 'linked' || $amazonus_status == 'ok') { + $markets[] = array( + 'name' => $this->language->get('text_amazonus'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 1 + ); + } else if ($amazonus_status == 'saved') { + $markets[] = array( + 'name' => $this->language->get('text_amazon'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 4 + ); + } else if ($amazonus_status == 'error_quick' || $amazonus_status == 'error_advanced' || $amazonus_status == 'error_few') { + $markets[] = array( + 'name' => $this->language->get('text_amazonus'), + 'text' => $this->language->get('button_error_fix'), + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 2 + ); + } else { + $markets[] = array( + 'name' => $this->language->get('text_amazonus'), + 'text' => $this->language->get('button_add'), + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 0 + ); + } + } + + if ($this->config->get('etsy_status') == '1') { + $this->load->model('extension/openbay/etsy_product'); + + $status = $this->model_extension_openbay_etsy_product->getStatus($result['product_id']); + + if ($status == 0) { + $markets[] = array( + 'name' => $this->language->get('text_etsy'), + 'text' => $this->language->get('button_add'), + 'href' => $this->url->link('extension/openbay/etsy_product/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 0 + ); + } else { + $markets[] = array( + 'name' => $this->language->get('text_etsy'), + 'text' => $this->language->get('button_edit'), + 'href' => $this->url->link('extension/openbay/etsy_product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'status' => 1 + ); + } + } + + if (!isset($result['has_option'])) { + $result['has_option'] = 0; + } + + $data['products'][] = array( + 'markets' => $markets, + 'product_id' => $result['product_id'], + 'name' => $result['name'], + 'model' => $result['model'], + 'price' => $result['price'], + 'special' => $special, + 'image' => $image, + 'quantity' => $result['quantity'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']), + 'edit' => $edit, + 'has_option' => $openstock_installed ? $result['has_option'] : 0, + 'vCount' => $openstock_installed ? $this->model_setting_module_openstock->countVariation($result['product_id']) : '', + 'vsCount' => $openstock_installed ? $this->model_setting_module_openstock->countVariationStock($result['product_id']) : '', + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + if (isset($this->session->data['warning'])) { + $data['error_warning'] = $this->session->data['warning']; + unset($this->session->data['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'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['filter_marketplace'])) { + $url .= '&filter_marketplace=' . $this->request->get['filter_marketplace']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true); + $data['sort_model'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=p.model' . $url, true); + $data['sort_price'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=p.price' . $url, true); + $data['sort_quantity'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=p.quantity' . $url, true); + $data['sort_status'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=p.status' . $url, true); + $data['sort_order'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . '&sort=p.sort_order' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['filter_marketplace'])) { + $url .= '&filter_marketplace=' . $this->request->get['filter_marketplace']; + } + + 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 = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + $data['filter_name'] = $filter_name; + $data['filter_model'] = $filter_model; + $data['filter_price'] = $filter_price; + $data['filter_price_to'] = $filter_price_to; + $data['filter_quantity'] = $filter_quantity; + $data['filter_quantity_to'] = $filter_quantity_to; + $data['filter_status'] = $filter_status; + $data['filter_sku'] = $filter_sku; + $data['filter_desc'] = $filter_desc; + $data['filter_category'] = $filter_category; + $data['filter_manufacturer'] = $filter_manufacturer; + $data['filter_marketplace'] = $filter_marketplace; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['ebay_status'] = $this->config->get('ebay_status'); + $data['user_token'] = $this->request->get['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/openbay_itemlist', $data)); + } + + public function itemlist() { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function eventDeleteProduct($route, $data) { + $this->openbay->log('eventDeleteProduct fired: ' . $route); + + foreach ($this->openbay->installed_markets as $market) { + if ($market == 'amazon') { + $status = $this->config->get('openbay_amazon_status'); + } elseif ($market == 'amazonus') { + $status = $this->config->get('openbay_amazonus_status'); + } else { + $status = $this->config->get($market . '_status'); + } + + if ($status == 1) { + $this->openbay->{$market}->deleteProduct((int)$data[0]); + } + } + } + + public function eventEditProduct($route, $data) { + $this->openbay->log('eventEditProduct fired: ' . $route); + + foreach ($this->openbay->installed_markets as $market) { + if ($market == 'amazon') { + $status = $this->config->get('openbay_amazon_status'); + } elseif ($market == 'amazonus') { + $status = $this->config->get('openbay_amazonus_status'); + } else { + $status = $this->config->get($market . '_status'); + } + + if ($status == 1) { + $this->openbay->{$market}->productUpdateListen((int)$data[0], $data[1]); + } + } + } + + public function eventMenu($route, &$data) { + // OpenBay Pro Menu + $openbay_menu = array(); + + $this->load->language('extension/openbay/openbay_menu'); + + if ($this->user->hasPermission('access', 'marketplace/openbay')) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_orders'), + 'href' => $this->url->link('marketplace/openbay/orderlist', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_items'), + 'href' => $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + // eBay sub menu + $ebay = array(); + + if ($this->user->hasPermission('access', 'extension/openbay/ebay') && $this->config->get('ebay_status') == 1) { + $ebay[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $ebay[] = array( + 'name' => $this->language->get('text_openbay_settings'), + 'href' => $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $ebay[] = array( + 'name' => $this->language->get('text_openbay_links'), + 'href' => $this->url->link('extension/openbay/ebay/viewitemlinks', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $ebay[] = array( + 'name' => $this->language->get('text_openbay_order_import'), + 'href' => $this->url->link('extension/openbay/ebay/vieworderimport', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($ebay) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_ebay'), + 'href' => '', + 'children' => $ebay + ); + } + + // Amazon EU sub menu + $amazon_eu = array(); + + if ($this->user->hasPermission('access', 'extension/openbay/amazon') && $this->config->get('openbay_amazon_status') == 1) { + $amazon_eu[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $amazon_eu[] = array( + 'name' => $this->language->get('text_openbay_settings'), + 'href' => $this->url->link('extension/openbay/amazon/settings', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $amazon_eu[] = array( + 'name' => $this->language->get('text_openbay_links'), + 'href' => $this->url->link('extension/openbay/amazon/itemlinks', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($amazon_eu) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_amazon'), + 'href' => '', + 'children' => $amazon_eu + ); + } + + // Amazon US sub menu + $amazon_us = array(); + + if ($this->user->hasPermission('access', 'extension/openbay/amazonus') && $this->config->get('openbay_amazonus_status') == 1) { + $amazon_us[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $amazon_us[] = array( + 'name' => $this->language->get('text_openbay_settings'), + 'href' => $this->url->link('extension/openbay/amazonus/settings', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $amazon_us[] = array( + 'name' => $this->language->get('text_openbay_links'), + 'href' => $this->url->link('extension/openbay/amazonus/itemlinks', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($amazon_us) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_amazonus'), + 'href' => '', + 'children' => $amazon_us + ); + } + + // Etsy sub menu + $etsy = array(); + + if ($this->user->hasPermission('access', 'extension/openbay/etsy') && $this->config->get('etsy_status') == 1) { + $etsy[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $etsy[] = array( + 'name' => $this->language->get('text_openbay_settings'), + 'href' => $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + if ($this->user->hasPermission('access', 'extension/openbay/etsy_product')) { + $etsy[] = array( + 'name' => $this->language->get('text_openbay_links'), + 'href' => $this->url->link('extension/openbay/etsy_product/links', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + } + + if ($etsy) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_etsy'), + 'href' => '', + 'children' => $etsy + ); + } + + // FBA sub menu + $fba = array(); + + if ($this->user->hasPermission('access', 'extension/openbay/fba') && $this->config->get('openbay_fba_status') == 1) { + $fba[] = array( + 'name' => $this->language->get('text_openbay_dashboard'), + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $fba[] = array( + 'name' => $this->language->get('text_openbay_settings'), + 'href' => $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $fba[] = array( + 'name' => $this->language->get('text_openbay_fulfillmentlist'), + 'href' => $this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + + $fba[] = array( + 'name' => $this->language->get('text_openbay_orderlist'), + 'href' => $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true), + 'children' => array() + ); + } + + if ($fba) { + $openbay_menu[] = array( + 'name' => $this->language->get('text_openbay_fba'), + 'href' => '', + 'children' => $fba + ); + } + } + + if ($openbay_menu) { + $data['menus'][] = array( + 'id' => 'menu-openbay', + 'icon' => 'fa-cubes', + 'name' => $this->language->get('text_openbay_extension'), + 'href' => '', + 'children' => $openbay_menu + ); + } + } + + public function purge() { + /** + * This is a function that is very dangerous + * Only developers should use this if you need to!! + * You need this code: **135** (includes stars) + * + * ACTIONS HERE CANNOT BE UNDONE WITHOUT A BACKUP + * + * !! IMPORTANT !! + * This section will by default comment out the database delete actions + * If you want to use them, uncomment. + * When you are finished, ensure you comment them back out! + */ + + $this->log->write('User is trying to wipe system data'); + + if ($this->request->post['pass'] != '**135**') { + $this->log->write('User failed password validation'); + $json = array('msg' => 'Password wrong, check the source code for the password! This is so you know what this feature does.'); + } else { + /** + $this->log->write('User passed validation'); + $this->db->query("TRUNCATE `" . DB_PREFIX . "order`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "order_history`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "order_option`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "order_product`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "order_total`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "customer`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "customer_activity`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "customer_ban_ip`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "customer_transaction`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "address`"); + + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_order`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_order_lock`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_transaction`"); + + if ($this->config->get('ebay_status') == 1) { + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_category`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_category_history`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_image_import`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_listing`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_listing_pending`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_stock_reserve`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_payment_method`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_profile`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_setting_option`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_shipping`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_shipping_location`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_shipping_location_exclude`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_template`"); + } + + if ($this->config->get('etsy_status') == 1) { + $this->db->query("TRUNCATE `" . DB_PREFIX . "etsy_listing`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "etsy_setting_option`"); + } + + $this->db->query("TRUNCATE `" . DB_PREFIX . "etsy_order`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "etsy_order_lock`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "manufacturer`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "manufacturer_to_store`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "attribute`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "attribute_description`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "attribute_group`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "attribute_group_description`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "ebay_listing`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "category`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "category_description`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "category_to_store`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_to_store`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_description`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_attribute`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_option`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_option_value`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_image`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_to_category`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "option`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "option_description`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "option_value`"); + $this->db->query("TRUNCATE `" . DB_PREFIX . "option_value_description`"); + + if ($this->openbay->addonLoad('openstock')) { + $this->db->query("TRUNCATE `" . DB_PREFIX . "product_option_relation`"); + } + */ + + $this->log->write('Data cleared'); + $json = array('msg' => 'Data cleared'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/report/online.php b/public/admin/controller/report/online.php new file mode 100644 index 0000000..ded8a11 --- /dev/null +++ b/public/admin/controller/report/online.php @@ -0,0 +1,121 @@ +<?php +class ControllerReportOnline extends Controller { + public function index() { + $this->load->language('report/online'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['refresh'] = $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('report/online'); + $this->load->model('customer/customer'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_ip' => $filter_ip, + 'filter_customer' => $filter_customer, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_report_online->getTotalOnline($filter_data); + + $results = $this->model_report_online->getOnline($filter_data); + + foreach ($results as $result) { + $customer_info = $this->model_customer_customer->getCustomer($result['customer_id']); + + if ($customer_info) { + $customer = $customer_info['firstname'] . ' ' . $customer_info['lastname']; + } else { + $customer = $this->language->get('text_guest'); + } + + $data['customers'][] = array( + 'customer_id' => $result['customer_id'], + 'ip' => $result['ip'], + 'customer' => $customer, + 'url' => $result['url'], + 'referer' => $result['referer'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_customer'] = $filter_customer; + $data['filter_ip'] = $filter_ip; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('report/online', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/report/report.php b/public/admin/controller/report/report.php new file mode 100644 index 0000000..c05a2cc --- /dev/null +++ b/public/admin/controller/report/report.php @@ -0,0 +1,72 @@ +<?php +class ControllerReportReport extends Controller { + public function index() { + $this->load->language('report/report'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['code'])) { + $data['code'] = $this->request->get['code']; + } else { + $data['code'] = ''; + } + + // Reports + $data['reports'] = array(); + + $this->load->model('setting/extension'); + + // Get a list of installed modules + $extensions = $this->model_setting_extension->getInstalled('report'); + + // Add all the modules which have multiple settings for each module + foreach ($extensions as $code) { + if ($this->config->get('report_' . $code . '_status') && $this->user->hasPermission('access', 'extension/report/' . $code)) { + $this->load->language('extension/report/' . $code, 'extension'); + + $data['reports'][] = array( + 'text' => $this->language->get('extension')->get('heading_title'), + 'code' => $code, + 'sort_order' => $this->config->get('report_' . $code . '_sort_order'), + 'href' => $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=' . $code, true) + ); + } + } + + $sort_order = array(); + + foreach ($data['reports'] as $key => $value) { + $sort_order[$key] = $value['sort_order']; + } + + array_multisort($sort_order, SORT_ASC, $data['reports']); + + if (isset($this->request->get['code'])) { + $data['report'] = $this->load->controller('extension/report/' . $this->request->get['code'] . '/report'); + } elseif (isset($data['reports'][0])) { + $data['report'] = $this->load->controller('extension/report/' . $data['reports'][0]['code'] . '/report'); + } else { + $data['report'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('report/report', $data)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/report/statistics.php b/public/admin/controller/report/statistics.php new file mode 100644 index 0000000..d9b623e --- /dev/null +++ b/public/admin/controller/report/statistics.php @@ -0,0 +1,262 @@ +<?php +class ControllerReportStatistics extends Controller { + private $error = array(); + + public function index() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + $this->getList(); + } + + public function ordersale() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('sale/order'); + + $this->model_report_statistics->editValue('order_sale', $this->model_sale_order->getTotalSales(array('filter_order_status' => implode(',', array_merge($this->config->get('config_complete_status'), $this->config->get('config_processing_status')))))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function orderprocessing() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('sale/order'); + + $this->model_report_statistics->editValue('order_processing', $this->model_sale_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_processing_status'))))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function ordercomplete() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('sale/order'); + + $this->model_report_statistics->editValue('order_complete', $this->model_sale_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_complete_status'))))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function orderother() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('localisation/order_status'); + + $order_status_data = array(); + + $results = $this->model_localisation_order_status->getOrderStatuses(); + + foreach ($results as $result) { + if (!in_array($result['order_status_id'], array_merge($this->config->get('config_complete_status'), $this->config->get('config_processing_status')))) { + $order_status_data[] = $result['order_status_id']; + } + } + + $this->load->model('sale/order'); + + $this->model_report_statistics->editValue('order_other', $this->model_sale_order->getTotalOrders(array('filter_order_status' => implode(',', $order_status_data)))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function returns() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('sale/return'); + + $this->model_report_statistics->editValue('return', $this->model_sale_return->getTotalReturns(array('filter_return_status_id' => $this->config->get('config_return_status_id')))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function customer() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('customer/customer'); + + $this->model_report_statistics->editValue('customer', $this->model_customer_customer->getTotalCustomers(array('filter_approved' => 0))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function affiliate() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('customer/customer'); + + $this->model_report_statistics->editValue('affiliate', $this->model_customer_customer->getTotalAffiliates(array('filter_approved' => 0))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function product() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('catalog/product'); + + $this->model_report_statistics->editValue('product', $this->model_catalog_product->getTotalProducts(array('filter_quantity' => 0))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function review() { + $this->load->language('report/statistics'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('report/statistics'); + + if ($this->validate()) { + $this->load->model('catalog/review'); + + $this->model_report_statistics->editValue('review', $this->model_catalog_review->getTotalReviews(array('filter_status' => 0))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + public function getList() { + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['statistics'] = array(); + + $this->load->model('report/statistics'); + + $results = $this->model_report_statistics->getStatistics(); + + foreach ($results as $result) { + $data['statistics'][] = array( + 'name' => $this->language->get('text_' . $result['code']), + 'value' => $result['value'], + 'href' => $this->url->link('report/statistics/' . str_replace('_', '', $result['code']), 'user_token=' . $this->session->data['user_token'], true) + ); + } + + 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'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('report/statistics', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'report/statistics')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/order.php b/public/admin/controller/sale/order.php new file mode 100644 index 0000000..cc56abc --- /dev/null +++ b/public/admin/controller/sale/order.php @@ -0,0 +1,1844 @@ +<?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 add() { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/order'); + + $this->getForm(); + } + + public function edit() { + $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->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + protected function getList() { + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_order_status'])) { + $filter_order_status = $this->request->get['filter_order_status']; + } else { + $filter_order_status = ''; + } + + 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 = ''; + } + + if (isset($this->request->get['filter_total'])) { + $filter_total = $this->request->get['filter_total']; + } else { + $filter_total = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['filter_date_modified'])) { + $filter_date_modified = $this->request->get['filter_date_modified']; + } else { + $filter_date_modified = ''; + } + + 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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['invoice'] = $this->url->link('sale/order/invoice', 'user_token=' . $this->session->data['user_token'], true); + $data['shipping'] = $this->url->link('sale/order/shipping', 'user_token=' . $this->session->data['user_token'], true); + $data['add'] = $this->url->link('sale/order/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = str_replace('&', '&', $this->url->link('sale/order/delete', 'user_token=' . $this->session->data['user_token'] . $url, true)); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_order_status' => $filter_order_status, + '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'], + 'order_status' => $result['order_status'] ? $result['order_status'] : $this->language->get('text_missing'), + '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'])), + 'shipping_code' => $result['shipping_code'], + 'view' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true), + 'edit' => $this->url->link('sale/order/edit', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'] . '&sort=o.order_id' . $url, true); + $data['sort_customer'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_status'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=order_status' . $url, true); + $data['sort_total'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.total' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_modified' . $url, true); + + $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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $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'] = $filter_order_status; + $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; + + $data['sort'] = $sort; + $data['order'] = $order; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + // API login + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_list', $data)); + } + + public function getForm() { + $data['text_form'] = !isset($this->request->get['order_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['cancel'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['order_id'])) { + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + } + + if (!empty($order_info)) { + $data['order_id'] = $this->request->get['order_id']; + $data['store_id'] = $order_info['store_id']; + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $data['customer'] = $order_info['customer']; + $data['customer_id'] = $order_info['customer_id']; + $data['customer_group_id'] = $order_info['customer_group_id']; + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + $data['email'] = $order_info['email']; + $data['telephone'] = $order_info['telephone']; + $data['account_custom_field'] = $order_info['custom_field']; + + $this->load->model('customer/customer'); + + $data['addresses'] = $this->model_customer_customer->getAddresses($order_info['customer_id']); + + $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_country_id'] = $order_info['payment_country_id']; + $data['payment_zone_id'] = $order_info['payment_zone_id']; + $data['payment_custom_field'] = $order_info['payment_custom_field']; + $data['payment_method'] = $order_info['payment_method']; + $data['payment_code'] = $order_info['payment_code']; + + $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_country_id'] = $order_info['shipping_country_id']; + $data['shipping_zone_id'] = $order_info['shipping_zone_id']; + $data['shipping_custom_field'] = $order_info['shipping_custom_field']; + $data['shipping_method'] = $order_info['shipping_method']; + $data['shipping_code'] = $order_info['shipping_code']; + + // Products + $data['order_products'] = array(); + + $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']); + + foreach ($products as $product) { + $data['order_products'][] = array( + 'product_id' => $product['product_id'], + 'name' => $product['name'], + 'model' => $product['model'], + 'option' => $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']), + 'quantity' => $product['quantity'], + 'price' => $product['price'], + 'total' => $product['total'], + 'reward' => $product['reward'] + ); + } + + // Vouchers + $data['order_vouchers'] = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']); + + $data['coupon'] = ''; + $data['voucher'] = ''; + $data['reward'] = ''; + + $data['order_totals'] = array(); + + $order_totals = $this->model_sale_order->getOrderTotals($this->request->get['order_id']); + + foreach ($order_totals as $order_total) { + // If coupon, voucher or reward points + $start = strpos($order_total['title'], '(') + 1; + $end = strrpos($order_total['title'], ')'); + + if ($start && $end) { + $data[$order_total['code']] = substr($order_total['title'], $start, $end - $start); + } + } + + $data['order_status_id'] = $order_info['order_status_id']; + $data['comment'] = $order_info['comment']; + $data['affiliate_id'] = $order_info['affiliate_id']; + $data['affiliate'] = $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname']; + $data['currency_code'] = $order_info['currency_code']; + } else { + $data['order_id'] = 0; + $data['store_id'] = 0; + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $data['customer'] = ''; + $data['customer_id'] = ''; + $data['customer_group_id'] = $this->config->get('config_customer_group_id'); + $data['firstname'] = ''; + $data['lastname'] = ''; + $data['email'] = ''; + $data['telephone'] = ''; + $data['customer_custom_field'] = array(); + + $data['addresses'] = array(); + + $data['payment_firstname'] = ''; + $data['payment_lastname'] = ''; + $data['payment_company'] = ''; + $data['payment_address_1'] = ''; + $data['payment_address_2'] = ''; + $data['payment_city'] = ''; + $data['payment_postcode'] = ''; + $data['payment_country_id'] = ''; + $data['payment_zone_id'] = ''; + $data['payment_custom_field'] = array(); + $data['payment_method'] = ''; + $data['payment_code'] = ''; + + $data['shipping_firstname'] = ''; + $data['shipping_lastname'] = ''; + $data['shipping_company'] = ''; + $data['shipping_address_1'] = ''; + $data['shipping_address_2'] = ''; + $data['shipping_city'] = ''; + $data['shipping_postcode'] = ''; + $data['shipping_country_id'] = ''; + $data['shipping_zone_id'] = ''; + $data['shipping_custom_field'] = array(); + $data['shipping_method'] = ''; + $data['shipping_code'] = ''; + + $data['order_products'] = array(); + $data['order_vouchers'] = array(); + $data['order_totals'] = array(); + + $data['order_status_id'] = $this->config->get('config_order_status_id'); + $data['comment'] = ''; + $data['affiliate_id'] = ''; + $data['affiliate'] = ''; + $data['currency_code'] = $this->config->get('config_currency'); + + $data['coupon'] = ''; + $data['voucher'] = ''; + $data['reward'] = ''; + } + + // Stores + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'store_id' => $result['store_id'], + 'name' => $result['name'] + ); + } + + // Customer Groups + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + // Custom Fields + $this->load->model('customer/custom_field'); + + $data['custom_fields'] = array(); + + $filter_data = array( + 'sort' => 'cf.sort_order', + 'order' => 'ASC' + ); + + $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($custom_fields as $custom_field) { + $data['custom_fields'][] = array( + 'custom_field_id' => $custom_field['custom_field_id'], + 'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']), + 'name' => $custom_field['name'], + 'value' => $custom_field['value'], + 'type' => $custom_field['type'], + 'location' => $custom_field['location'], + 'sort_order' => $custom_field['sort_order'] + ); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $data['voucher_min'] = $this->config->get('config_voucher_min'); + + $this->load->model('sale/voucher_theme'); + + $data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes(); + + // API login + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_form', $data)); + } + + 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['text_ip_add'] = sprintf($this->language->get('text_ip_add'), $this->request->server['REMOTE_ADDR']); + $data['text_order'] = sprintf($this->language->get('text_order'), $this->request->get['order_id']); + + $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'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['shipping'] = $this->url->link('sale/order/shipping', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['invoice'] = $this->url->link('sale/order/invoice', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['edit'] = $this->url->link('sale/order/edit', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['cancel'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['store_id'] = $order_info['store_id']; + $data['store_name'] = $order_info['store_name']; + + if ($order_info['store_id'] == 0) { + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + } else { + $data['store_url'] = $order_info['store_url']; + } + + if ($order_info['invoice_no']) { + $data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no']; + } else { + $data['invoice_no'] = ''; + } + + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); + + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + + if ($order_info['customer_id']) { + $data['customer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['customer_id'], true); + } else { + $data['customer'] = ''; + } + + $this->load->model('customer/customer_group'); + + $customer_group_info = $this->model_customer_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['shipping_method'] = $order_info['shipping_method']; + $data['payment_method'] = $order_info['payment_method']; + + // Payment Address + 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'] + ); + + $data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + // Shipping Address + 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'] + ); + + $data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + // Uploaded files + $this->load->model('tool/upload'); + + $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 { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $option_data[] = array( + 'name' => $option['name'], + 'value' => $upload_info['name'], + 'type' => $option['type'], + 'href' => $this->url->link('tool/upload/download', 'user_token=' . $this->session->data['user_token'] . '&code=' . $upload_info['code'], true) + ); + } + } + } + + $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/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true) + ); + } + + $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/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $voucher['voucher_id'], true) + ); + } + + $data['totals'] = array(); + + $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['comment'] = nl2br($order_info['comment']); + + $this->load->model('customer/customer'); + + $data['reward'] = $order_info['reward']; + + $data['reward_total'] = $this->model_customer_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('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['affiliate_id'], true); + } else { + $data['affiliate'] = ''; + } + + $data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']); + + $this->load->model('customer/customer'); + + $data['commission_total'] = $this->model_customer_customer->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['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['order_status_id'] = $order_info['order_status_id']; + + $data['account_custom_field'] = $order_info['custom_field']; + + // Custom Fields + $this->load->model('customer/custom_field'); + + $data['account_custom_fields'] = array(); + + $filter_data = array( + 'sort' => 'cf.sort_order', + 'order' => 'ASC' + ); + + $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'account' && isset($order_info['custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['custom_field'][$custom_field['custom_field_id']] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'] + ); + } + } + } + } + + // Custom fields + $data['payment_custom_fields'] = array(); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'address' && isset($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['payment_custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['payment_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['payment_custom_field'][$custom_field['custom_field_id']], + 'sort_order' => $custom_field['sort_order'] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['payment_custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + } + + // Shipping + $data['shipping_custom_fields'] = array(); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'address' && isset($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['shipping_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['shipping_custom_field'][$custom_field['custom_field_id']], + 'sort_order' => $custom_field['sort_order'] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + } + + $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']; + + // Additional Tabs + $data['tabs'] = array(); + + if ($this->user->hasPermission('access', 'extension/payment/' . $order_info['payment_code'])) { + if (is_file(DIR_CATALOG . 'controller/extension/payment/' . $order_info['payment_code'] . '.php')) { + $content = $this->load->controller('extension/payment/' . $order_info['payment_code'] . '/order'); + } else { + $content = ''; + } + + if ($content) { + $this->load->language('extension/payment/' . $order_info['payment_code']); + + $data['tabs'][] = array( + 'code' => $order_info['payment_code'], + 'title' => $this->language->get('heading_title'), + 'content' => $content + ); + } + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('fraud'); + + foreach ($extensions as $extension) { + if ($this->config->get('fraud_' . $extension . '_status')) { + $this->load->language('extension/fraud/' . $extension, 'extension'); + + $content = $this->load->controller('extension/fraud/' . $extension . '/order'); + + if ($content) { + $data['tabs'][] = array( + 'code' => $extension, + 'title' => $this->language->get('extension')->get('heading_title'), + 'content' => $content + ); + } + } + } + + // The URL we send API requests to + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_info', $data)); + } else { + return new Action('error/not_found'); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'sale/order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + 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->addHeader('Content-Type: application/json'); + $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('customer/customer'); + + $reward_total = $this->model_customer_customer->getTotalCustomerRewardsByOrderId($order_id); + + if (!$reward_total) { + $this->model_customer_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->addHeader('Content-Type: application/json'); + $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('customer/customer'); + + $this->model_customer_customer->deleteReward($order_id); + } + + $json['success'] = $this->language->get('text_reward_removed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $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('customer/customer'); + + $affiliate_total = $this->model_customer_customer->getTotalTransactionsByOrderId($order_id); + + if (!$affiliate_total) { + $this->model_customer_customer->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->addHeader('Content-Type: application/json'); + $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('customer/customer'); + + $this->model_customer_customer->deleteTransactionByOrderId($order_id); + } + + $json['success'] = $this->language->get('text_commission_removed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function history() { + $this->load->language('sale/order'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $this->load->model('sale/order'); + + $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', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/order_history', $data)); + } + + 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'); + + $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)))); + + $this->load->model('tool/upload'); + + $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 { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $value = $upload_info['name']; + } else { + $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', $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'); + + $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_code']) { + $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']; + } else { + $store_address = $this->config->get('config_address'); + $store_email = $this->config->get('config_email'); + $store_telephone = $this->config->get('config_telephone'); + } + + 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)))); + + $this->load->model('tool/upload'); + + $product_data = array(); + + $products = $this->model_sale_order->getOrderProducts($order_id); + + foreach ($products as $product) { + $option_weight = ''; + + $product_info = $this->model_catalog_product->getProduct($product['product_id']); + + if ($product_info) { + $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 { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $value = $upload_info['name']; + } else { + $value = ''; + } + } + + $option_data[] = array( + 'name' => $option['name'], + 'value' => $value + ); + + $product_option_value_info = $this->model_catalog_product->getProductOptionValue($product['product_id'], $option['product_option_value_id']); + + if ($product_option_value_info) { + if ($product_option_value_info['weight_prefix'] == '+') { + $option_weight += $product_option_value_info['weight']; + } elseif ($product_option_value_info['weight_prefix'] == '-') { + $option_weight -= $product_option_value_info['weight']; + } + } + } + + $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'], + 'weight' => $this->weight->format(($product_info['weight'] + (float)$option_weight) * $product['quantity'], $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')) + ); + } + } + + $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, + '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', $data)); + } +} diff --git a/public/admin/controller/sale/recurring.php b/public/admin/controller/sale/recurring.php new file mode 100644 index 0000000..b54a633 --- /dev/null +++ b/public/admin/controller/sale/recurring.php @@ -0,0 +1,432 @@ +<?php +class ControllerSaleRecurring extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/recurring'); + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_order_recurring_id'])) { + $filter_order_recurring_id = $this->request->get['filter_order_recurring_id']; + } else { + $filter_order_recurring_id = ''; + } + + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_reference'])) { + $filter_reference = $this->request->get['filter_reference']; + } else { + $filter_reference = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = 0; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'order_recurring_id'; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + 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_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . $this->request->get['filter_reference']; + } + + 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_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['recurrings'] = array(); + + $filter_data = array( + 'filter_order_recurring_id' => $filter_order_recurring_id, + 'filter_order_id' => $filter_order_id, + 'filter_reference' => $filter_reference, + 'filter_customer' => $filter_customer, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'order' => $order, + 'sort' => $sort, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $recurrings_total = $this->model_sale_recurring->getTotalRecurrings($filter_data); + + $results = $this->model_sale_recurring->getRecurrings($filter_data); + + foreach ($results as $result) { + if ($result['status']) { + $status = $this->language->get('text_status_' . $result['status']); + } else { + $status = ''; + } + + $data['recurrings'][] = array( + 'order_recurring_id' => $result['order_recurring_id'], + 'order_id' => $result['order_id'], + 'reference' => $result['reference'], + 'customer' => $result['customer'], + 'status' => $status, + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'view' => $this->url->link('sale/recurring/info', 'user_token=' . $this->session->data['user_token'] . '&order_recurring_id=' . $result['order_recurring_id'] . $url, true), + 'order' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_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'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . urlencode(html_entity_decode($this->request->get['filter_reference'], ENT_QUOTES, 'UTF-8')); + } + + 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_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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_recurring'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.order_recurring_id' . $url, true); + $data['sort_order'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.order_id' . $url, true); + $data['sort_reference'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.reference' . $url, true); + $data['sort_customer'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_status'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . urlencode(html_entity_decode($this->request->get['filter_reference'], ENT_QUOTES, 'UTF-8')); + } + + 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_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $recurrings_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&page={page}' . $url, true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($recurrings_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($recurrings_total - $this->config->get('config_limit_admin'))) ? $recurrings_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $recurrings_total, ceil($recurrings_total / $this->config->get('config_limit_admin'))); + + $data['filter_order_recurring_id'] = $filter_order_recurring_id; + $data['filter_order_id'] = $filter_order_id; + $data['filter_reference'] = $filter_reference; + $data['filter_customer'] = $filter_customer; + $data['filter_status'] = $filter_status; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['recurring_statuses'] = array(); + + $data['recurring_statuses'][0] = array( + 'text' => '', + 'value' => 0 + ); + + for ($i = 1; $i <= 6; $i++) { + $data['recurring_statuses'][$i] = array( + 'text' => $this->language->get('text_status_' . $i), + 'value' => 1 + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/recurring_list', $data)); + } + + public function info() { + $this->load->model('sale/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $order_recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + if ($order_recurring_info) { + $this->load->language('sale/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->request->get['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . $this->request->get['filter_reference']; + } + + 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_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['cancel'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true); + + // Recurring + $data['order_recurring_id'] = $order_recurring_info['order_recurring_id']; + $data['reference'] = $order_recurring_info['reference']; + $data['recurring_name'] = $order_recurring_info['recurring_name']; + + if ($order_recurring_info['recurring_id']) { + $data['recurring'] = $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $order_recurring_info['recurring_id'], true); + } else { + $data['recurring'] = ''; + } + + $data['recurring_description'] = $order_recurring_info['recurring_description']; + + if ($order_recurring_info['status']) { + $data['recurring_status']= $this->language->get('text_status_' . $order_recurring_info['status']); + } else { + $data['recurring_status'] = ''; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_recurring_info['order_id']); + + $data['payment_method'] = $order_info['payment_method']; + + // Order + $data['order_id'] = $order_info['order_id']; + $data['order'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_info['order_id'], true); + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + + if ($order_info['customer_id']) { + $data['customer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['customer_id'], true); + } else { + $data['customer'] = ''; + } + + $data['email'] = $order_info['email']; + $data['order_status'] = $order_info['order_status']; + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); + + // Product + $data['product'] = $order_recurring_info['product_name']; + $data['quantity'] = $order_recurring_info['product_quantity']; + + // Transactions + $data['transactions'] = array(); + + $transactions = $this->model_sale_recurring->getRecurringTransactions($order_recurring_info['order_recurring_id']); + + foreach ($transactions as $transaction) { + $data['transactions'][] = array( + 'date_added' => $transaction['date_added'], + 'type' => $transaction['type'], + 'amount' => $this->currency->format($transaction['amount'], $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $data['buttons'] = $this->load->controller('extension/payment/' . $order_info['payment_code'] . '/recurringButtons'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/recurring_info', $data)); + } else { + return new Action('error/not_found'); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/return.php b/public/admin/controller/sale/return.php new file mode 100644 index 0000000..80b48f5 --- /dev/null +++ b/public/admin/controller/sale/return.php @@ -0,0 +1,919 @@ +<?php +class ControllerSaleReturn extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_return->addReturn($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_return->editReturn($this->request->get['return_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_id) { + $this->model_sale_return->deleteReturn($return_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_return_id'])) { + $filter_return_id = $this->request->get['filter_return_id']; + } else { + $filter_return_id = ''; + } + + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_product'])) { + $filter_product = $this->request->get['filter_product']; + } else { + $filter_product = ''; + } + + if (isset($this->request->get['filter_model'])) { + $filter_model = $this->request->get['filter_model']; + } else { + $filter_model = ''; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $filter_return_status_id = $this->request->get['filter_return_status_id']; + } else { + $filter_return_status_id = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['filter_date_modified'])) { + $filter_date_modified = $this->request->get['filter_date_modified']; + } else { + $filter_date_modified = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'r.return_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_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/return/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/return/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['returns'] = array(); + + $filter_data = array( + 'filter_return_id' => $filter_return_id, + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_product' => $filter_product, + 'filter_model' => $filter_model, + 'filter_return_status_id' => $filter_return_status_id, + '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') + ); + + $return_total = $this->model_sale_return->getTotalReturns($filter_data); + + $results = $this->model_sale_return->getReturns($filter_data); + + foreach ($results as $result) { + $data['returns'][] = array( + 'return_id' => $result['return_id'], + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'product' => $result['product'], + 'model' => $result['model'], + 'return_status' => $result['return_status'], + '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'])), + 'edit' => $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $result['return_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + + unset($this->session->data['error']); + } elseif (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_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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_return_id'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.return_id' . $url, true); + $data['sort_order_id'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.order_id' . $url, true); + $data['sort_customer'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_product'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.product' . $url, true); + $data['sort_model'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.model' . $url, true); + $data['sort_status'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_modified' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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 = $return_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_total - $this->config->get('config_limit_admin'))) ? $return_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_total, ceil($return_total / $this->config->get('config_limit_admin'))); + + $data['filter_return_id'] = $filter_return_id; + $data['filter_order_id'] = $filter_order_id; + $data['filter_customer'] = $filter_customer; + $data['filter_product'] = $filter_product; + $data['filter_model'] = $filter_model; + $data['filter_return_status_id'] = $filter_return_status_id; + $data['filter_date_added'] = $filter_date_added; + $data['filter_date_modified'] = $filter_date_modified; + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/return_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['return_id'])) { + $data['return_id'] = $this->request->get['return_id']; + } else { + $data['return_id'] = 0; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['order_id'])) { + $data['error_order_id'] = $this->error['order_id']; + } else { + $data['error_order_id'] = ''; + } + + 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['product'])) { + $data['error_product'] = $this->error['product']; + } else { + $data['error_product'] = ''; + } + + if (isset($this->error['model'])) { + $data['error_model'] = $this->error['model']; + } else { + $data['error_model'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + 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_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_id'])) { + $data['action'] = $this->url->link('sale/return/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $this->request->get['return_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['return_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $return_info = $this->model_sale_return->getReturn($this->request->get['return_id']); + } + + if (isset($this->request->post['order_id'])) { + $data['order_id'] = $this->request->post['order_id']; + } elseif (!empty($return_info)) { + $data['order_id'] = $return_info['order_id']; + } else { + $data['order_id'] = ''; + } + + if (isset($this->request->post['date_ordered'])) { + $data['date_ordered'] = $this->request->post['date_ordered']; + } elseif (!empty($return_info)) { + $data['date_ordered'] = ($return_info['date_ordered'] != '0000-00-00' ? $return_info['date_ordered'] : ''); + } else { + $data['date_ordered'] = ''; + } + + if (isset($this->request->post['customer'])) { + $data['customer'] = $this->request->post['customer']; + } elseif (!empty($return_info)) { + $data['customer'] = $return_info['customer']; + } else { + $data['customer'] = ''; + } + + if (isset($this->request->post['customer_id'])) { + $data['customer_id'] = $this->request->post['customer_id']; + } elseif (!empty($return_info)) { + $data['customer_id'] = $return_info['customer_id']; + } else { + $data['customer_id'] = ''; + } + + if (isset($this->request->post['firstname'])) { + $data['firstname'] = $this->request->post['firstname']; + } elseif (!empty($return_info)) { + $data['firstname'] = $return_info['firstname']; + } else { + $data['firstname'] = ''; + } + + if (isset($this->request->post['lastname'])) { + $data['lastname'] = $this->request->post['lastname']; + } elseif (!empty($return_info)) { + $data['lastname'] = $return_info['lastname']; + } else { + $data['lastname'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } elseif (!empty($return_info)) { + $data['email'] = $return_info['email']; + } else { + $data['email'] = ''; + } + + if (isset($this->request->post['telephone'])) { + $data['telephone'] = $this->request->post['telephone']; + } elseif (!empty($return_info)) { + $data['telephone'] = $return_info['telephone']; + } else { + $data['telephone'] = ''; + } + + if (isset($this->request->post['product'])) { + $data['product'] = $this->request->post['product']; + } elseif (!empty($return_info)) { + $data['product'] = $return_info['product']; + } else { + $data['product'] = ''; + } + + if (isset($this->request->post['product_id'])) { + $data['product_id'] = $this->request->post['product_id']; + } elseif (!empty($return_info)) { + $data['product_id'] = $return_info['product_id']; + } else { + $data['product_id'] = ''; + } + + if (isset($this->request->post['model'])) { + $data['model'] = $this->request->post['model']; + } elseif (!empty($return_info)) { + $data['model'] = $return_info['model']; + } else { + $data['model'] = ''; + } + + if (isset($this->request->post['quantity'])) { + $data['quantity'] = $this->request->post['quantity']; + } elseif (!empty($return_info)) { + $data['quantity'] = $return_info['quantity']; + } else { + $data['quantity'] = ''; + } + + if (isset($this->request->post['opened'])) { + $data['opened'] = $this->request->post['opened']; + } elseif (!empty($return_info)) { + $data['opened'] = $return_info['opened']; + } else { + $data['opened'] = ''; + } + + if (isset($this->request->post['return_reason_id'])) { + $data['return_reason_id'] = $this->request->post['return_reason_id']; + } elseif (!empty($return_info)) { + $data['return_reason_id'] = $return_info['return_reason_id']; + } else { + $data['return_reason_id'] = ''; + } + + $this->load->model('localisation/return_reason'); + + $data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons(); + + if (isset($this->request->post['return_action_id'])) { + $data['return_action_id'] = $this->request->post['return_action_id']; + } elseif (!empty($return_info)) { + $data['return_action_id'] = $return_info['return_action_id']; + } else { + $data['return_action_id'] = ''; + } + + $this->load->model('localisation/return_action'); + + $data['return_actions'] = $this->model_localisation_return_action->getReturnActions(); + + if (isset($this->request->post['comment'])) { + $data['comment'] = $this->request->post['comment']; + } elseif (!empty($return_info)) { + $data['comment'] = $return_info['comment']; + } else { + $data['comment'] = ''; + } + + if (isset($this->request->post['return_status_id'])) { + $data['return_status_id'] = $this->request->post['return_status_id']; + } elseif (!empty($return_info)) { + $data['return_status_id'] = $return_info['return_status_id']; + } else { + $data['return_status_id'] = ''; + } + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/return_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['order_id'])) { + $this->error['order_id'] = $this->language->get('error_order_id'); + } + + 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) || !filter_var($this->request->post['email'], FILTER_VALIDATE_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['product']) < 1) || (utf8_strlen($this->request->post['product']) > 255)) { + $this->error['product'] = $this->language->get('error_product'); + } + + if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) { + $this->error['model'] = $this->language->get('error_model'); + } + + if (empty($this->request->post['return_reason_id'])) { + $this->error['reason'] = $this->language->get('error_reason'); + } + + 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/return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function history() { + $this->load->language('sale/return'); + + $this->load->model('sale/return'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_sale_return->getReturnHistories($this->request->get['return_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_return->getTotalReturnHistories($this->request->get['return_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('sale/return/history', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $this->request->get['return_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/return_history', $data)); + } + + public function addHistory() { + $this->load->language('sale/return'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/return')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('sale/return'); + + $this->model_sale_return->addReturnHistory($this->request->get['return_id'], $this->request->post['return_status_id'], $this->request->post['comment'], $this->request->post['notify']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/voucher.php b/public/admin/controller/sale/voucher.php new file mode 100644 index 0000000..8317183 --- /dev/null +++ b/public/admin/controller/sale/voucher.php @@ -0,0 +1,679 @@ +<?php +class ControllerSaleVoucher extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher->addVoucher($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher->editVoucher($this->request->get['voucher_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $voucher_id) { + $this->model_sale_voucher->deleteVoucher($voucher_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'v.date_added'; + } + + 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['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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/voucher/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/voucher/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['vouchers'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $voucher_total = $this->model_sale_voucher->getTotalVouchers(); + + $results = $this->model_sale_voucher->getVouchers($filter_data); + + foreach ($results as $result) { + if ($result['order_id']) { + $order_href = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true); + } else { + $order_href = ''; + } + + $data['vouchers'][] = array( + 'voucher_id' => $result['voucher_id'], + 'code' => $result['code'], + 'from' => $result['from_name'], + 'to' => $result['to_name'], + 'theme' => $result['theme'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('sale/voucher/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $result['voucher_id'] . $url, true), + 'order' => $order_href + ); + } + + $data['user_token'] = $this->session->data['user_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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_code'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.code' . $url, true); + $data['sort_from'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.from_name' . $url, true); + $data['sort_to'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.to_name' . $url, true); + $data['sort_theme'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=theme' . $url, true); + $data['sort_amount'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.amount' . $url, true); + $data['sort_status'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.date_added' . $url, true); + + $url = ''; + + 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 = $voucher_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($voucher_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($voucher_total - $this->config->get('config_limit_admin'))) ? $voucher_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $voucher_total, ceil($voucher_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['voucher_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->request->get['voucher_id'])) { + $data['voucher_id'] = $this->request->get['voucher_id']; + } else { + $data['voucher_id'] = 0; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + if (isset($this->error['from_name'])) { + $data['error_from_name'] = $this->error['from_name']; + } else { + $data['error_from_name'] = ''; + } + + if (isset($this->error['from_email'])) { + $data['error_from_email'] = $this->error['from_email']; + } else { + $data['error_from_email'] = ''; + } + + if (isset($this->error['to_name'])) { + $data['error_to_name'] = $this->error['to_name']; + } else { + $data['error_to_name'] = ''; + } + + if (isset($this->error['to_email'])) { + $data['error_to_email'] = $this->error['to_email']; + } else { + $data['error_to_email'] = ''; + } + + if (isset($this->error['amount'])) { + $data['error_amount'] = $this->error['amount']; + } else { + $data['error_amount'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['voucher_id'])) { + $data['action'] = $this->url->link('sale/voucher/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/voucher/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $this->request->get['voucher_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['voucher_id']) && (!$this->request->server['REQUEST_METHOD'] != 'POST')) { + $voucher_info = $this->model_sale_voucher->getVoucher($this->request->get['voucher_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($voucher_info)) { + $data['code'] = $voucher_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['from_name'])) { + $data['from_name'] = $this->request->post['from_name']; + } elseif (!empty($voucher_info)) { + $data['from_name'] = $voucher_info['from_name']; + } else { + $data['from_name'] = ''; + } + + if (isset($this->request->post['from_email'])) { + $data['from_email'] = $this->request->post['from_email']; + } elseif (!empty($voucher_info)) { + $data['from_email'] = $voucher_info['from_email']; + } else { + $data['from_email'] = ''; + } + + if (isset($this->request->post['to_name'])) { + $data['to_name'] = $this->request->post['to_name']; + } elseif (!empty($voucher_info)) { + $data['to_name'] = $voucher_info['to_name']; + } else { + $data['to_name'] = ''; + } + + if (isset($this->request->post['to_email'])) { + $data['to_email'] = $this->request->post['to_email']; + } elseif (!empty($voucher_info)) { + $data['to_email'] = $voucher_info['to_email']; + } else { + $data['to_email'] = ''; + } + + $this->load->model('sale/voucher_theme'); + + $data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes(); + + if (isset($this->request->post['voucher_theme_id'])) { + $data['voucher_theme_id'] = $this->request->post['voucher_theme_id']; + } elseif (!empty($voucher_info)) { + $data['voucher_theme_id'] = $voucher_info['voucher_theme_id']; + } else { + $data['voucher_theme_id'] = ''; + } + + if (isset($this->request->post['message'])) { + $data['message'] = $this->request->post['message']; + } elseif (!empty($voucher_info)) { + $data['message'] = $voucher_info['message']; + } else { + $data['message'] = ''; + } + + if (isset($this->request->post['amount'])) { + $data['amount'] = $this->request->post['amount']; + } elseif (!empty($voucher_info)) { + $data['amount'] = $voucher_info['amount']; + } else { + $data['amount'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($voucher_info)) { + $data['status'] = $voucher_info['status']; + } else { + $data['status'] = true; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['code']) < 3) || (utf8_strlen($this->request->post['code']) > 10)) { + $this->error['code'] = $this->language->get('error_code'); + } + + $voucher_info = $this->model_sale_voucher->getVoucherByCode($this->request->post['code']); + + if ($voucher_info) { + if (!isset($this->request->get['voucher_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } elseif ($voucher_info['voucher_id'] != $this->request->get['voucher_id']) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + if ((utf8_strlen($this->request->post['to_name']) < 1) || (utf8_strlen($this->request->post['to_name']) > 64)) { + $this->error['to_name'] = $this->language->get('error_to_name'); + } + + if ((utf8_strlen($this->request->post['to_email']) > 96) || !filter_var($this->request->post['to_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['to_email'] = $this->language->get('error_email'); + } + + if ((utf8_strlen($this->request->post['from_name']) < 1) || (utf8_strlen($this->request->post['from_name']) > 64)) { + $this->error['from_name'] = $this->language->get('error_from_name'); + } + + if ((utf8_strlen($this->request->post['from_email']) > 96) || !filter_var($this->request->post['from_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['from_email'] = $this->language->get('error_email'); + } + + if ($this->request->post['amount'] < 1) { + $this->error['amount'] = $this->language->get('error_amount'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $voucher_id) { + $order_voucher_info = $this->model_sale_order->getOrderVoucherByVoucherId($voucher_id); + + if ($order_voucher_info) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_voucher_info['order_id'], true)); + + break; + } + } + + return !$this->error; + } + + public function history() { + $this->load->language('sale/voucher'); + + $this->load->model('sale/voucher'); + + $data['text_no_results'] = $this->language->get('text_no_results'); + + $data['column_order_id'] = $this->language->get('column_order_id'); + $data['column_customer'] = $this->language->get('column_customer'); + $data['column_amount'] = $this->language->get('column_amount'); + $data['column_date_added'] = $this->language->get('column_date_added'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_sale_voucher->getVoucherHistories($this->request->get['voucher_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_sale_voucher->getTotalVoucherHistories($this->request->get['voucher_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('sale/voucher/history', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $this->request->get['voucher_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/voucher_history', $data)); + } + + public function send() { + $this->load->language('mail/voucher'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + $this->load->model('sale/voucher'); + + $vouchers = array(); + + if (isset($this->request->post['selected'])) { + $vouchers = $this->request->post['selected']; + } elseif (isset($this->request->post['voucher_id'])) { + $vouchers[] = $this->request->post['voucher_id']; + } + + if ($vouchers) { + foreach ($vouchers as $voucher_id) { + $voucher_info = $this->model_sale_voucher->getVoucher($voucher_id); + + if ($voucher_info) { + if ($voucher_info['order_id']) { + $order_id = $voucher_info['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + // If voucher belongs to an order + if ($order_info) { + $this->load->model('localisation/language'); + + $language = new Language($order_info['language_code']); + $language->load($order_info['language_code']); + $language->load('mail/voucher'); + + // HTML Mail + $data['title'] = sprintf($language->get('text_subject'), $voucher_info['from_name']); + + $data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($voucher_info['amount'], (!empty($order_info['currency_code']) ? $order_info['currency_code'] : $this->config->get('config_currency')), (!empty($order_info['currency_value']) ? $order_info['currency_value'] : $this->currency->getValue($this->config->get('config_currency'))))); + $data['text_from'] = sprintf($language->get('text_from'), $voucher_info['from_name']); + $data['text_message'] = $language->get('text_message'); + $data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher_info['code']); + $data['text_footer'] = $language->get('text_footer'); + + $this->load->model('sale/voucher_theme'); + + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); + + if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $data['store_name'] = $order_info['store_name']; + $data['store_url'] = $order_info['store_url']; + $data['message'] = nl2br($voucher_info['message']); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($voucher_info['to_email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); + $mail->setSubject(sprintf($language->get('text_subject'), html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8'))); + $mail->setHtml($this->load->view('mail/voucher', $data)); + $mail->send(); + + // If voucher does not belong to an order + } else { + $data['title'] = sprintf($this->language->get('text_subject'), $voucher_info['from_name']); + + $data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency'))); + $data['text_from'] = sprintf($this->language->get('text_from'), $voucher_info['from_name']); + $data['text_message'] = $this->language->get('text_message'); + $data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']); + $data['text_footer'] = $this->language->get('text_footer'); + + $this->load->model('sale/voucher_theme'); + + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); + + if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $data['store_name'] = $this->config->get('config_name'); + $data['store_url'] = HTTP_CATALOG; + $data['message'] = nl2br($voucher_info['message']); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($voucher_info['to_email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); + $mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), $voucher_info['from_name']), ENT_QUOTES, 'UTF-8')); + $mail->setHtml($this->load->view('mail/voucher', $data)); + $mail->send(); + } + } + } + + $json['success'] = $this->language->get('text_sent'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/voucher_theme.php b/public/admin/controller/sale/voucher_theme.php new file mode 100644 index 0000000..e2e4bee --- /dev/null +++ b/public/admin/controller/sale/voucher_theme.php @@ -0,0 +1,381 @@ +<?php +class ControllerSaleVoucherTheme extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher_theme->addVoucherTheme($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher_theme->editVoucherTheme($this->request->get['voucher_theme_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $voucher_theme_id) { + $this->model_sale_voucher_theme->deleteVoucherTheme($voucher_theme_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'vtd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/voucher_theme/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/voucher_theme/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['voucher_themes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $voucher_theme_total = $this->model_sale_voucher_theme->getTotalVoucherThemes(); + + $results = $this->model_sale_voucher_theme->getVoucherThemes($filter_data); + + foreach ($results as $result) { + $data['voucher_themes'][] = array( + 'voucher_theme_id' => $result['voucher_theme_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('sale/voucher_theme/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_theme_id=' . $result['voucher_theme_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $voucher_theme_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($voucher_theme_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($voucher_theme_total - $this->config->get('config_limit_admin'))) ? $voucher_theme_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $voucher_theme_total, ceil($voucher_theme_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_theme_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['voucher_theme_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['image'])) { + $data['error_image'] = $this->error['image']; + } else { + $data['error_image'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['voucher_theme_id'])) { + $data['action'] = $this->url->link('sale/voucher_theme/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/voucher_theme/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_theme_id=' . $this->request->get['voucher_theme_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['voucher_theme_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($this->request->get['voucher_theme_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['voucher_theme_description'])) { + $data['voucher_theme_description'] = $this->request->post['voucher_theme_description']; + } elseif (isset($this->request->get['voucher_theme_id'])) { + $data['voucher_theme_description'] = $this->model_sale_voucher_theme->getVoucherThemeDescriptions($this->request->get['voucher_theme_id']); + } else { + $data['voucher_theme_description'] = array(); + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($voucher_theme_info)) { + $data['image'] = $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($voucher_theme_info) && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($voucher_theme_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_theme_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/voucher_theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['voucher_theme_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + if (!$this->request->post['image']) { + $this->error['image'] = $this->language->get('error_image'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'sale/voucher_theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/voucher'); + + foreach ($this->request->post['selected'] as $voucher_theme_id) { + $voucher_total = $this->model_sale_voucher->getTotalVouchersByVoucherThemeId($voucher_theme_id); + + if ($voucher_total) { + $this->error['warning'] = sprintf($this->language->get('error_voucher'), $voucher_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/setting/setting.php b/public/admin/controller/setting/setting.php new file mode 100644 index 0000000..558b64b --- /dev/null +++ b/public/admin/controller/setting/setting.php @@ -0,0 +1,982 @@ +<?php +class ControllerSettingSetting extends Controller { + private $error = array(); + + public function index() { + $this->load->language('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('config', $this->request->post); + + if ($this->config->get('config_currency_auto')) { + $this->load->model('localisation/currency'); + + $this->model_localisation_currency->refresh(); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['owner'])) { + $data['error_owner'] = $this->error['owner']; + } else { + $data['error_owner'] = ''; + } + + if (isset($this->error['address'])) { + $data['error_address'] = $this->error['address']; + } else { + $data['error_address'] = ''; + } + + 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['meta_title'])) { + $data['error_meta_title'] = $this->error['meta_title']; + } else { + $data['error_meta_title'] = ''; + } + + if (isset($this->error['country'])) { + $data['error_country'] = $this->error['country']; + } else { + $data['error_country'] = ''; + } + + if (isset($this->error['zone'])) { + $data['error_zone'] = $this->error['zone']; + } else { + $data['error_zone'] = ''; + } + + if (isset($this->error['customer_group_display'])) { + $data['error_customer_group_display'] = $this->error['customer_group_display']; + } else { + $data['error_customer_group_display'] = ''; + } + + if (isset($this->error['login_attempts'])) { + $data['error_login_attempts'] = $this->error['login_attempts']; + } else { + $data['error_login_attempts'] = ''; + } + + if (isset($this->error['voucher_min'])) { + $data['error_voucher_min'] = $this->error['voucher_min']; + } else { + $data['error_voucher_min'] = ''; + } + + if (isset($this->error['voucher_max'])) { + $data['error_voucher_max'] = $this->error['voucher_max']; + } else { + $data['error_voucher_max'] = ''; + } + + if (isset($this->error['processing_status'])) { + $data['error_processing_status'] = $this->error['processing_status']; + } else { + $data['error_processing_status'] = ''; + } + + if (isset($this->error['complete_status'])) { + $data['error_complete_status'] = $this->error['complete_status']; + } else { + $data['error_complete_status'] = ''; + } + + if (isset($this->error['log'])) { + $data['error_log'] = $this->error['log']; + } else { + $data['error_log'] = ''; + } + + if (isset($this->error['limit_admin'])) { + $data['error_limit_admin'] = $this->error['limit_admin']; + } else { + $data['error_limit_admin'] = ''; + } + + if (isset($this->error['encryption'])) { + $data['error_encryption'] = $this->error['encryption']; + } else { + $data['error_encryption'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_stores'), + 'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true) + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['action'] = $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['config_meta_title'])) { + $data['config_meta_title'] = $this->request->post['config_meta_title']; + } else { + $data['config_meta_title'] = $this->config->get('config_meta_title'); + } + + if (isset($this->request->post['config_meta_description'])) { + $data['config_meta_description'] = $this->request->post['config_meta_description']; + } else { + $data['config_meta_description'] = $this->config->get('config_meta_description'); + } + + if (isset($this->request->post['config_meta_keyword'])) { + $data['config_meta_keyword'] = $this->request->post['config_meta_keyword']; + } else { + $data['config_meta_keyword'] = $this->config->get('config_meta_keyword'); + } + + if (isset($this->request->post['config_theme'])) { + $data['config_theme'] = $this->request->post['config_theme']; + } else { + $data['config_theme'] = $this->config->get('config_theme'); + } + + if ($this->request->server['HTTPS']) { + $data['store_url'] = HTTPS_CATALOG; + } else { + $data['store_url'] = HTTP_CATALOG; + } + + $data['themes'] = array(); + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('theme'); + + foreach ($extensions as $code) { + $this->load->language('extension/theme/' . $code, 'extension'); + + $data['themes'][] = array( + 'text' => $this->language->get('extension')->get('heading_title'), + 'value' => $code + ); + } + + if (isset($this->request->post['config_layout_id'])) { + $data['config_layout_id'] = $this->request->post['config_layout_id']; + } else { + $data['config_layout_id'] = $this->config->get('config_layout_id'); + } + + $this->load->model('design/layout'); + + $data['layouts'] = $this->model_design_layout->getLayouts(); + + if (isset($this->request->post['config_name'])) { + $data['config_name'] = $this->request->post['config_name']; + } else { + $data['config_name'] = $this->config->get('config_name'); + } + + if (isset($this->request->post['config_owner'])) { + $data['config_owner'] = $this->request->post['config_owner']; + } else { + $data['config_owner'] = $this->config->get('config_owner'); + } + + if (isset($this->request->post['config_address'])) { + $data['config_address'] = $this->request->post['config_address']; + } else { + $data['config_address'] = $this->config->get('config_address'); + } + + if (isset($this->request->post['config_geocode'])) { + $data['config_geocode'] = $this->request->post['config_geocode']; + } else { + $data['config_geocode'] = $this->config->get('config_geocode'); + } + + if (isset($this->request->post['config_email'])) { + $data['config_email'] = $this->request->post['config_email']; + } else { + $data['config_email'] = $this->config->get('config_email'); + } + + if (isset($this->request->post['config_telephone'])) { + $data['config_telephone'] = $this->request->post['config_telephone']; + } else { + $data['config_telephone'] = $this->config->get('config_telephone'); + } + + if (isset($this->request->post['config_fax'])) { + $data['config_fax'] = $this->request->post['config_fax']; + } else { + $data['config_fax'] = $this->config->get('config_fax'); + } + + if (isset($this->request->post['config_image'])) { + $data['config_image'] = $this->request->post['config_image']; + } else { + $data['config_image'] = $this->config->get('config_image'); + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['config_image']) && is_file(DIR_IMAGE . $this->request->post['config_image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['config_image'], 100, 100); + } elseif ($this->config->get('config_image') && is_file(DIR_IMAGE . $this->config->get('config_image'))) { + $data['thumb'] = $this->model_tool_image->resize($this->config->get('config_image'), 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['config_open'])) { + $data['config_open'] = $this->request->post['config_open']; + } else { + $data['config_open'] = $this->config->get('config_open'); + } + + if (isset($this->request->post['config_comment'])) { + $data['config_comment'] = $this->request->post['config_comment']; + } else { + $data['config_comment'] = $this->config->get('config_comment'); + } + + $this->load->model('localisation/location'); + + $data['locations'] = $this->model_localisation_location->getLocations(); + + if (isset($this->request->post['config_location'])) { + $data['config_location'] = $this->request->post['config_location']; + } elseif ($this->config->get('config_location')) { + $data['config_location'] = $this->config->get('config_location'); + } else { + $data['config_location'] = array(); + } + + if (isset($this->request->post['config_country_id'])) { + $data['config_country_id'] = $this->request->post['config_country_id']; + } else { + $data['config_country_id'] = $this->config->get('config_country_id'); + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + if (isset($this->request->post['config_zone_id'])) { + $data['config_zone_id'] = $this->request->post['config_zone_id']; + } else { + $data['config_zone_id'] = $this->config->get('config_zone_id'); + } + + if (isset($this->request->post['config_language'])) { + $data['config_language'] = $this->request->post['config_language']; + } else { + $data['config_language'] = $this->config->get('config_language'); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['config_admin_language'])) { + $data['config_admin_language'] = $this->request->post['config_admin_language']; + } else { + $data['config_admin_language'] = $this->config->get('config_admin_language'); + } + + if (isset($this->request->post['config_currency'])) { + $data['config_currency'] = $this->request->post['config_currency']; + } else { + $data['config_currency'] = $this->config->get('config_currency'); + } + + if (isset($this->request->post['config_currency_auto'])) { + $data['config_currency_auto'] = $this->request->post['config_currency_auto']; + } else { + $data['config_currency_auto'] = $this->config->get('config_currency_auto'); + } + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + if (isset($this->request->post['config_length_class_id'])) { + $data['config_length_class_id'] = $this->request->post['config_length_class_id']; + } else { + $data['config_length_class_id'] = $this->config->get('config_length_class_id'); + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['config_weight_class_id'])) { + $data['config_weight_class_id'] = $this->request->post['config_weight_class_id']; + } else { + $data['config_weight_class_id'] = $this->config->get('config_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['config_limit_admin'])) { + $data['config_limit_admin'] = $this->request->post['config_limit_admin']; + } else { + $data['config_limit_admin'] = $this->config->get('config_limit_admin'); + } + + if (isset($this->request->post['config_product_count'])) { + $data['config_product_count'] = $this->request->post['config_product_count']; + } else { + $data['config_product_count'] = $this->config->get('config_product_count'); + } + + if (isset($this->request->post['config_review_status'])) { + $data['config_review_status'] = $this->request->post['config_review_status']; + } else { + $data['config_review_status'] = $this->config->get('config_review_status'); + } + + if (isset($this->request->post['config_review_guest'])) { + $data['config_review_guest'] = $this->request->post['config_review_guest']; + } else { + $data['config_review_guest'] = $this->config->get('config_review_guest'); + } + + if (isset($this->request->post['config_voucher_min'])) { + $data['config_voucher_min'] = $this->request->post['config_voucher_min']; + } else { + $data['config_voucher_min'] = $this->config->get('config_voucher_min'); + } + + if (isset($this->request->post['config_voucher_max'])) { + $data['config_voucher_max'] = $this->request->post['config_voucher_max']; + } else { + $data['config_voucher_max'] = $this->config->get('config_voucher_max'); + } + + if (isset($this->request->post['config_tax'])) { + $data['config_tax'] = $this->request->post['config_tax']; + } else { + $data['config_tax'] = $this->config->get('config_tax'); + } + + if (isset($this->request->post['config_tax_default'])) { + $data['config_tax_default'] = $this->request->post['config_tax_default']; + } else { + $data['config_tax_default'] = $this->config->get('config_tax_default'); + } + + if (isset($this->request->post['config_tax_customer'])) { + $data['config_tax_customer'] = $this->request->post['config_tax_customer']; + } else { + $data['config_tax_customer'] = $this->config->get('config_tax_customer'); + } + + if (isset($this->request->post['config_customer_online'])) { + $data['config_customer_online'] = $this->request->post['config_customer_online']; + } else { + $data['config_customer_online'] = $this->config->get('config_customer_online'); + } + + if (isset($this->request->post['config_customer_activity'])) { + $data['config_customer_activity'] = $this->request->post['config_customer_activity']; + } else { + $data['config_customer_activity'] = $this->config->get('config_customer_activity'); + } + + if (isset($this->request->post['config_customer_search'])) { + $data['config_customer_search'] = $this->request->post['config_customer_search']; + } else { + $data['config_customer_search'] = $this->config->get('config_customer_search'); + } + + if (isset($this->request->post['config_customer_group_id'])) { + $data['config_customer_group_id'] = $this->request->post['config_customer_group_id']; + } else { + $data['config_customer_group_id'] = $this->config->get('config_customer_group_id'); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['config_customer_group_display'])) { + $data['config_customer_group_display'] = $this->request->post['config_customer_group_display']; + } elseif ($this->config->get('config_customer_group_display')) { + $data['config_customer_group_display'] = $this->config->get('config_customer_group_display'); + } else { + $data['config_customer_group_display'] = array(); + } + + if (isset($this->request->post['config_customer_price'])) { + $data['config_customer_price'] = $this->request->post['config_customer_price']; + } else { + $data['config_customer_price'] = $this->config->get('config_customer_price'); + } + + if (isset($this->request->post['config_login_attempts'])) { + $data['config_login_attempts'] = $this->request->post['config_login_attempts']; + } elseif ($this->config->has('config_login_attempts')) { + $data['config_login_attempts'] = $this->config->get('config_login_attempts'); + } else { + $data['config_login_attempts'] = 5; + } + + if (isset($this->request->post['config_account_id'])) { + $data['config_account_id'] = $this->request->post['config_account_id']; + } else { + $data['config_account_id'] = $this->config->get('config_account_id'); + } + + $this->load->model('catalog/information'); + + $data['informations'] = $this->model_catalog_information->getInformations(); + + if (isset($this->request->post['config_cart_weight'])) { + $data['config_cart_weight'] = $this->request->post['config_cart_weight']; + } else { + $data['config_cart_weight'] = $this->config->get('config_cart_weight'); + } + + if (isset($this->request->post['config_checkout_guest'])) { + $data['config_checkout_guest'] = $this->request->post['config_checkout_guest']; + } else { + $data['config_checkout_guest'] = $this->config->get('config_checkout_guest'); + } + + if (isset($this->request->post['config_checkout_id'])) { + $data['config_checkout_id'] = $this->request->post['config_checkout_id']; + } else { + $data['config_checkout_id'] = $this->config->get('config_checkout_id'); + } + + if (isset($this->request->post['config_invoice_prefix'])) { + $data['config_invoice_prefix'] = $this->request->post['config_invoice_prefix']; + } elseif ($this->config->get('config_invoice_prefix')) { + $data['config_invoice_prefix'] = $this->config->get('config_invoice_prefix'); + } else { + $data['config_invoice_prefix'] = 'INV-' . date('Y') . '-00'; + } + + if (isset($this->request->post['config_order_status_id'])) { + $data['config_order_status_id'] = $this->request->post['config_order_status_id']; + } else { + $data['config_order_status_id'] = $this->config->get('config_order_status_id'); + } + + if (isset($this->request->post['config_processing_status'])) { + $data['config_processing_status'] = $this->request->post['config_processing_status']; + } elseif ($this->config->get('config_processing_status')) { + $data['config_processing_status'] = $this->config->get('config_processing_status'); + } else { + $data['config_processing_status'] = array(); + } + + if (isset($this->request->post['config_complete_status'])) { + $data['config_complete_status'] = $this->request->post['config_complete_status']; + } elseif ($this->config->get('config_complete_status')) { + $data['config_complete_status'] = $this->config->get('config_complete_status'); + } else { + $data['config_complete_status'] = array(); + } + + if (isset($this->request->post['config_fraud_status_id'])) { + $data['config_fraud_status_id'] = $this->request->post['config_fraud_status_id']; + } else { + $data['config_fraud_status_id'] = $this->config->get('config_fraud_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['config_api_id'])) { + $data['config_api_id'] = $this->request->post['config_api_id']; + } else { + $data['config_api_id'] = $this->config->get('config_api_id'); + } + + $this->load->model('user/api'); + + $data['apis'] = $this->model_user_api->getApis(); + + if (isset($this->request->post['config_stock_display'])) { + $data['config_stock_display'] = $this->request->post['config_stock_display']; + } else { + $data['config_stock_display'] = $this->config->get('config_stock_display'); + } + + if (isset($this->request->post['config_stock_warning'])) { + $data['config_stock_warning'] = $this->request->post['config_stock_warning']; + } else { + $data['config_stock_warning'] = $this->config->get('config_stock_warning'); + } + + if (isset($this->request->post['config_stock_checkout'])) { + $data['config_stock_checkout'] = $this->request->post['config_stock_checkout']; + } else { + $data['config_stock_checkout'] = $this->config->get('config_stock_checkout'); + } + + if (isset($this->request->post['config_affiliate_group_id'])) { + $data['config_affiliate_group_id'] = $this->request->post['config_affiliate_group_id']; + } else { + $data['config_affiliate_group_id'] = $this->config->get('config_affiliate_group_id'); + } + + if (isset($this->request->post['config_affiliate_approval'])) { + $data['config_affiliate_approval'] = $this->request->post['config_affiliate_approval']; + } elseif ($this->config->has('config_affiliate_approval')) { + $data['config_affiliate_approval'] = $this->config->get('config_affiliate_approval'); + } else { + $data['config_affiliate_approval'] = ''; + } + + if (isset($this->request->post['config_affiliate_auto'])) { + $data['config_affiliate_auto'] = $this->request->post['config_affiliate_auto']; + } elseif ($this->config->has('config_affiliate_auto')) { + $data['config_affiliate_auto'] = $this->config->get('config_affiliate_auto'); + } else { + $data['config_affiliate_auto'] = ''; + } + + if (isset($this->request->post['config_affiliate_commission'])) { + $data['config_affiliate_commission'] = $this->request->post['config_affiliate_commission']; + } elseif ($this->config->has('config_affiliate_commission')) { + $data['config_affiliate_commission'] = $this->config->get('config_affiliate_commission'); + } else { + $data['config_affiliate_commission'] = '5.00'; + } + + if (isset($this->request->post['config_affiliate_id'])) { + $data['config_affiliate_id'] = $this->request->post['config_affiliate_id']; + } else { + $data['config_affiliate_id'] = $this->config->get('config_affiliate_id'); + } + + if (isset($this->request->post['config_return_id'])) { + $data['config_return_id'] = $this->request->post['config_return_id']; + } else { + $data['config_return_id'] = $this->config->get('config_return_id'); + } + + if (isset($this->request->post['config_return_status_id'])) { + $data['config_return_status_id'] = $this->request->post['config_return_status_id']; + } else { + $data['config_return_status_id'] = $this->config->get('config_return_status_id'); + } + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + if (isset($this->request->post['config_captcha'])) { + $data['config_captcha'] = $this->request->post['config_captcha']; + } else { + $data['config_captcha'] = $this->config->get('config_captcha'); + } + + $this->load->model('setting/extension'); + + $data['captchas'] = array(); + + // Get a list of installed captchas + $extensions = $this->model_setting_extension->getInstalled('captcha'); + + foreach ($extensions as $code) { + $this->load->language('extension/captcha/' . $code, 'extension'); + + if ($this->config->get('captcha_' . $code . '_status')) { + $data['captchas'][] = array( + 'text' => $this->language->get('extension')->get('heading_title'), + 'value' => $code + ); + } + } + + if (isset($this->request->post['config_captcha_page'])) { + $data['config_captcha_page'] = $this->request->post['config_captcha_page']; + } elseif ($this->config->has('config_captcha_page')) { + $data['config_captcha_page'] = $this->config->get('config_captcha_page'); + } else { + $data['config_captcha_page'] = array(); + } + + $data['captcha_pages'] = array(); + + $data['captcha_pages'][] = array( + 'text' => $this->language->get('text_register'), + 'value' => 'register' + ); + + $data['captcha_pages'][] = array( + 'text' => $this->language->get('text_guest'), + 'value' => 'guest' + ); + + $data['captcha_pages'][] = array( + 'text' => $this->language->get('text_review'), + 'value' => 'review' + ); + + $data['captcha_pages'][] = array( + 'text' => $this->language->get('text_return'), + 'value' => 'return' + ); + + $data['captcha_pages'][] = array( + 'text' => $this->language->get('text_contact'), + 'value' => 'contact' + ); + + if (isset($this->request->post['config_logo'])) { + $data['config_logo'] = $this->request->post['config_logo']; + } else { + $data['config_logo'] = $this->config->get('config_logo'); + } + + if (isset($this->request->post['config_logo']) && is_file(DIR_IMAGE . $this->request->post['config_logo'])) { + $data['logo'] = $this->model_tool_image->resize($this->request->post['config_logo'], 100, 100); + } elseif ($this->config->get('config_logo') && is_file(DIR_IMAGE . $this->config->get('config_logo'))) { + $data['logo'] = $this->model_tool_image->resize($this->config->get('config_logo'), 100, 100); + } else { + $data['logo'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + if (isset($this->request->post['config_icon'])) { + $data['config_icon'] = $this->request->post['config_icon']; + } else { + $data['config_icon'] = $this->config->get('config_icon'); + } + + if (isset($this->request->post['config_icon']) && is_file(DIR_IMAGE . $this->request->post['config_icon'])) { + $data['icon'] = $this->model_tool_image->resize($this->request->post['config_icon'], 100, 100); + } elseif ($this->config->get('config_icon') && is_file(DIR_IMAGE . $this->config->get('config_icon'))) { + $data['icon'] = $this->model_tool_image->resize($this->config->get('config_icon'), 100, 100); + } else { + $data['icon'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + if (isset($this->request->post['config_mail_engine'])) { + $data['config_mail_engine'] = $this->request->post['config_mail_engine']; + } else { + $data['config_mail_engine'] = $this->config->get('config_mail_engine'); + } + + if (isset($this->request->post['config_mail_parameter'])) { + $data['config_mail_parameter'] = $this->request->post['config_mail_parameter']; + } else { + $data['config_mail_parameter'] = $this->config->get('config_mail_parameter'); + } + + if (isset($this->request->post['config_mail_smtp_hostname'])) { + $data['config_mail_smtp_hostname'] = $this->request->post['config_mail_smtp_hostname']; + } else { + $data['config_mail_smtp_hostname'] = $this->config->get('config_mail_smtp_hostname'); + } + + if (isset($this->request->post['config_mail_smtp_username'])) { + $data['config_mail_smtp_username'] = $this->request->post['config_mail_smtp_username']; + } else { + $data['config_mail_smtp_username'] = $this->config->get('config_mail_smtp_username'); + } + + if (isset($this->request->post['config_mail_smtp_password'])) { + $data['config_mail_smtp_password'] = $this->request->post['config_mail_smtp_password']; + } else { + $data['config_mail_smtp_password'] = $this->config->get('config_mail_smtp_password'); + } + + if (isset($this->request->post['config_mail_smtp_port'])) { + $data['config_mail_smtp_port'] = $this->request->post['config_mail_smtp_port']; + } elseif ($this->config->has('config_mail_smtp_port')) { + $data['config_mail_smtp_port'] = $this->config->get('config_mail_smtp_port'); + } else { + $data['config_mail_smtp_port'] = 25; + } + + if (isset($this->request->post['config_mail_smtp_timeout'])) { + $data['config_mail_smtp_timeout'] = $this->request->post['config_mail_smtp_timeout']; + } elseif ($this->config->has('config_mail_smtp_timeout')) { + $data['config_mail_smtp_timeout'] = $this->config->get('config_mail_smtp_timeout'); + } else { + $data['config_mail_smtp_timeout'] = 5; + } + + if (isset($this->request->post['config_mail_alert'])) { + $data['config_mail_alert'] = $this->request->post['config_mail_alert']; + } elseif ($this->config->has('config_mail_alert')) { + $data['config_mail_alert'] = $this->config->get('config_mail_alert'); + } else { + $data['config_mail_alert'] = array(); + } + + $data['mail_alerts'] = array(); + + $data['mail_alerts'][] = array( + 'text' => $this->language->get('text_mail_account'), + 'value' => 'account' + ); + + $data['mail_alerts'][] = array( + 'text' => $this->language->get('text_mail_affiliate'), + 'value' => 'affiliate' + ); + + $data['mail_alerts'][] = array( + 'text' => $this->language->get('text_mail_order'), + 'value' => 'order' + ); + + $data['mail_alerts'][] = array( + 'text' => $this->language->get('text_mail_review'), + 'value' => 'review' + ); + + if (isset($this->request->post['config_mail_alert_email'])) { + $data['config_mail_alert_email'] = $this->request->post['config_mail_alert_email']; + } else { + $data['config_mail_alert_email'] = $this->config->get('config_mail_alert_email'); + } + + if (isset($this->request->post['config_secure'])) { + $data['config_secure'] = $this->request->post['config_secure']; + } else { + $data['config_secure'] = $this->config->get('config_secure'); + } + + if (isset($this->request->post['config_shared'])) { + $data['config_shared'] = $this->request->post['config_shared']; + } else { + $data['config_shared'] = $this->config->get('config_shared'); + } + + if (isset($this->request->post['config_robots'])) { + $data['config_robots'] = $this->request->post['config_robots']; + } else { + $data['config_robots'] = $this->config->get('config_robots'); + } + + if (isset($this->request->post['config_seo_url'])) { + $data['config_seo_url'] = $this->request->post['config_seo_url']; + } else { + $data['config_seo_url'] = $this->config->get('config_seo_url'); + } + + if (isset($this->request->post['config_file_max_size'])) { + $data['config_file_max_size'] = $this->request->post['config_file_max_size']; + } elseif ($this->config->get('config_file_max_size')) { + $data['config_file_max_size'] = $this->config->get('config_file_max_size'); + } else { + $data['config_file_max_size'] = 300000; + } + + if (isset($this->request->post['config_file_ext_allowed'])) { + $data['config_file_ext_allowed'] = $this->request->post['config_file_ext_allowed']; + } else { + $data['config_file_ext_allowed'] = $this->config->get('config_file_ext_allowed'); + } + + if (isset($this->request->post['config_file_mime_allowed'])) { + $data['config_file_mime_allowed'] = $this->request->post['config_file_mime_allowed']; + } else { + $data['config_file_mime_allowed'] = $this->config->get('config_file_mime_allowed'); + } + + if (isset($this->request->post['config_maintenance'])) { + $data['config_maintenance'] = $this->request->post['config_maintenance']; + } else { + $data['config_maintenance'] = $this->config->get('config_maintenance'); + } + + if (isset($this->request->post['config_password'])) { + $data['config_password'] = $this->request->post['config_password']; + } else { + $data['config_password'] = $this->config->get('config_password'); + } + + if (isset($this->request->post['config_encryption'])) { + $data['config_encryption'] = $this->request->post['config_encryption']; + } else { + $data['config_encryption'] = $this->config->get('config_encryption'); + } + + if (isset($this->request->post['config_compression'])) { + $data['config_compression'] = $this->request->post['config_compression']; + } else { + $data['config_compression'] = $this->config->get('config_compression'); + } + + if (isset($this->request->post['config_error_display'])) { + $data['config_error_display'] = $this->request->post['config_error_display']; + } else { + $data['config_error_display'] = $this->config->get('config_error_display'); + } + + if (isset($this->request->post['config_error_log'])) { + $data['config_error_log'] = $this->request->post['config_error_log']; + } else { + $data['config_error_log'] = $this->config->get('config_error_log'); + } + + if (isset($this->request->post['config_error_filename'])) { + $data['config_error_filename'] = $this->request->post['config_error_filename']; + } else { + $data['config_error_filename'] = $this->config->get('config_error_filename'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('setting/setting', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'setting/setting')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['config_meta_title']) { + $this->error['meta_title'] = $this->language->get('error_meta_title'); + } + + if (!$this->request->post['config_name']) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['config_owner']) < 3) || (utf8_strlen($this->request->post['config_owner']) > 64)) { + $this->error['owner'] = $this->language->get('error_owner'); + } + + if ((utf8_strlen($this->request->post['config_address']) < 3) || (utf8_strlen($this->request->post['config_address']) > 256)) { + $this->error['address'] = $this->language->get('error_address'); + } + + if ((utf8_strlen($this->request->post['config_email']) > 96) || !filter_var($this->request->post['config_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + if ((utf8_strlen($this->request->post['config_telephone']) < 3) || (utf8_strlen($this->request->post['config_telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + if (!empty($this->request->post['config_customer_group_display']) && !in_array($this->request->post['config_customer_group_id'], $this->request->post['config_customer_group_display'])) { + $this->error['customer_group_display'] = $this->language->get('error_customer_group_display'); + } + + if (!$this->request->post['config_limit_admin']) { + $this->error['limit_admin'] = $this->language->get('error_limit'); + } + + if ($this->request->post['config_login_attempts'] < 1) { + $this->error['login_attempts'] = $this->language->get('error_login_attempts'); + } + + if (!$this->request->post['config_voucher_min']) { + $this->error['voucher_min'] = $this->language->get('error_voucher_min'); + } + + if (!$this->request->post['config_voucher_max']) { + $this->error['voucher_max'] = $this->language->get('error_voucher_max'); + } + + if (!isset($this->request->post['config_processing_status'])) { + $this->error['processing_status'] = $this->language->get('error_processing_status'); + } + + if (!isset($this->request->post['config_complete_status'])) { + $this->error['complete_status'] = $this->language->get('error_complete_status'); + } + + if (!$this->request->post['config_error_filename']) { + $this->error['log'] = $this->language->get('error_log_required'); + } elseif (preg_match('/\.\.[\/\\\]?/', $this->request->post['config_error_filename'])) { + $this->error['log'] = $this->language->get('error_log_invalid'); + } elseif (substr($this->request->post['config_error_filename'], strrpos($this->request->post['config_error_filename'], '.')) != '.log') { + $this->error['log'] = $this->language->get('error_log_extension'); + } + + if ((utf8_strlen($this->request->post['config_encryption']) < 32) || (utf8_strlen($this->request->post['config_encryption']) > 1024)) { + $this->error['encryption'] = $this->language->get('error_encryption'); + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + public function theme() { + if ($this->request->server['HTTPS']) { + $server = HTTPS_CATALOG; + } else { + $server = HTTP_CATALOG; + } + + // This is only here for compatibility with old themes. + if ($this->request->get['theme'] == 'theme_default') { + $theme = $this->config->get('theme_default_directory'); + } else { + $theme = basename($this->request->get['theme']); + } + + if (is_file(DIR_CATALOG . 'view/theme/' . $theme . '/image/' . $theme . '.png')) { + $this->response->setOutput($server . 'catalog/view/theme/' . $theme . '/image/' . $theme . '.png'); + } else { + $this->response->setOutput($server . 'image/no_image.png'); + } + } +} diff --git a/public/admin/controller/setting/store.php b/public/admin/controller/setting/store.php new file mode 100644 index 0000000..1596ce1 --- /dev/null +++ b/public/admin/controller/setting/store.php @@ -0,0 +1,717 @@ +<?php +class ControllerSettingStore extends Controller { + private $error = array(); + + public function index() { + $this->load->language('setting/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/store'); + + $this->load->model('setting/setting'); + + $this->getList(); + } + + public function add() { + $this->load->language('setting/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/store'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $store_id = $this->model_setting_store->addStore($this->request->post); + + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('config', $this->request->post, $store_id); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('setting/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/store'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_setting_store->editStore($this->request->get['store_id'], $this->request->post); + + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('config', $this->request->post, $this->request->get['store_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('setting/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/store'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + $this->load->model('setting/setting'); + + foreach ($this->request->post['selected'] as $store_id) { + $this->model_setting_store->deleteStore($store_id); + + $this->model_setting_setting->deleteSetting('config', $store_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->getList(); + } + + protected function getList() { + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['add'] = $this->url->link('setting/store/add', 'user_token=' . $this->session->data['user_token'], true); + $data['delete'] = $this->url->link('setting/store/delete', 'user_token=' . $this->session->data['user_token'], true); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->config->get('config_name') . $this->language->get('text_default'), + 'url' => $this->config->get('config_secure') ? HTTPS_CATALOG : HTTP_CATALOG, + 'edit' => $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true) + ); + + $store_total = $this->model_setting_store->getTotalStores(); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'store_id' => $result['store_id'], + 'name' => $result['name'], + 'url' => $result['url'], + 'edit' => $this->url->link('setting/store/edit', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $result['store_id'], true) + ); + } + + 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(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('setting/store_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['store_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['url'])) { + $data['error_url'] = $this->error['url']; + } else { + $data['error_url'] = ''; + } + + if (isset($this->error['meta_title'])) { + $data['error_meta_title'] = $this->error['meta_title']; + } else { + $data['error_meta_title'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['owner'])) { + $data['error_owner'] = $this->error['owner']; + } else { + $data['error_owner'] = ''; + } + + if (isset($this->error['address'])) { + $data['error_address'] = $this->error['address']; + } else { + $data['error_address'] = ''; + } + + 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['customer_group_display'])) { + $data['error_customer_group_display'] = $this->error['customer_group_display']; + } else { + $data['error_customer_group_display'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true) + ); + + if (!isset($this->request->get['store_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_settings'), + 'href' => $this->url->link('setting/store/add', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_settings'), + 'href' => $this->url->link('setting/store/edit', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true) + ); + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (!isset($this->request->get['store_id'])) { + $data['action'] = $this->url->link('setting/store/add', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('setting/store/edit', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true); + } + + $data['cancel'] = $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->get['store_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $this->load->model('setting/setting'); + + $store_info = $this->model_setting_setting->getSetting('config', $this->request->get['store_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['config_url'])) { + $data['config_url'] = $this->request->post['config_url']; + } elseif (isset($store_info['config_url'])) { + $data['config_url'] = $store_info['config_url']; + } else { + $data['config_url'] = ''; + } + + if (isset($this->request->post['config_ssl'])) { + $data['config_ssl'] = $this->request->post['config_ssl']; + } elseif (isset($store_info['config_ssl'])) { + $data['config_ssl'] = $store_info['config_ssl']; + } else { + $data['config_ssl'] = ''; + } + + if (isset($this->request->post['config_meta_title'])) { + $data['config_meta_title'] = $this->request->post['config_meta_title']; + } elseif (isset($store_info['config_meta_title'])) { + $data['config_meta_title'] = $store_info['config_meta_title']; + } else { + $data['config_meta_title'] = ''; + } + + if (isset($this->request->post['config_meta_description'])) { + $data['config_meta_description'] = $this->request->post['config_meta_description']; + } elseif (isset($store_info['config_meta_description'])) { + $data['config_meta_description'] = $store_info['config_meta_description']; + } else { + $data['config_meta_description'] = ''; + } + + if (isset($this->request->post['config_meta_keyword'])) { + $data['config_meta_keyword'] = $this->request->post['config_meta_keyword']; + } elseif (isset($store_info['config_meta_keyword'])) { + $data['config_meta_keyword'] = $store_info['config_meta_keyword']; + } else { + $data['config_meta_keyword'] = ''; + } + + if (isset($this->request->post['config_theme'])) { + $data['config_theme'] = $this->request->post['config_theme']; + } elseif (isset($store_info['config_theme'])) { + $data['config_theme'] = $store_info['config_theme']; + } else { + $data['config_theme'] = ''; + } + + $data['themes'] = array(); + + // Create a new language container so we don't pollute the current one + $language = new Language($this->config->get('config_language')); + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('theme'); + + foreach ($extensions as $code) { + $this->load->language('extension/theme/' . $code, 'extension'); + + $data['themes'][] = array( + 'text' => $this->language->get('extension')->get('heading_title'), + 'value' => $code + ); + } + + if (isset($this->request->post['config_layout_id'])) { + $data['config_layout_id'] = $this->request->post['config_layout_id']; + } elseif (isset($store_info['config_layout_id'])) { + $data['config_layout_id'] = $store_info['config_layout_id']; + } else { + $data['config_layout_id'] = ''; + } + + $this->load->model('design/layout'); + + $data['layouts'] = $this->model_design_layout->getLayouts(); + + if (isset($this->request->post['config_name'])) { + $data['config_name'] = $this->request->post['config_name']; + } elseif (isset($store_info['config_name'])) { + $data['config_name'] = $store_info['config_name']; + } else { + $data['config_name'] = ''; + } + + if (isset($this->request->post['config_owner'])) { + $data['config_owner'] = $this->request->post['config_owner']; + } elseif (isset($store_info['config_owner'])) { + $data['config_owner'] = $store_info['config_owner']; + } else { + $data['config_owner'] = ''; + } + + if (isset($this->request->post['config_address'])) { + $data['config_address'] = $this->request->post['config_address']; + } elseif (isset($store_info['config_address'])) { + $data['config_address'] = $store_info['config_address']; + } else { + $data['config_address'] = ''; + } + + if (isset($this->request->post['config_geocode'])) { + $data['config_geocode'] = $this->request->post['config_geocode']; + } elseif (isset($store_info['config_geocode'])) { + $data['config_geocode'] = $store_info['config_geocode']; + } else { + $data['config_geocode'] = ''; + } + + if (isset($this->request->post['config_email'])) { + $data['config_email'] = $this->request->post['config_email']; + } elseif (isset($store_info['config_email'])) { + $data['config_email'] = $store_info['config_email']; + } else { + $data['config_email'] = ''; + } + + if (isset($this->request->post['config_telephone'])) { + $data['config_telephone'] = $this->request->post['config_telephone']; + } elseif (isset($store_info['config_telephone'])) { + $data['config_telephone'] = $store_info['config_telephone']; + } else { + $data['config_telephone'] = ''; + } + + if (isset($this->request->post['config_fax'])) { + $data['config_fax'] = $this->request->post['config_fax']; + } elseif (isset($store_info['config_fax'])) { + $data['config_fax'] = $store_info['config_fax']; + } else { + $data['config_fax'] = ''; + } + + if (isset($this->request->post['config_image'])) { + $data['config_image'] = $this->request->post['config_image']; + } elseif (isset($store_info['config_image'])) { + $data['config_image'] = $store_info['config_image']; + } else { + $data['config_image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['config_image']) && is_file(DIR_IMAGE . $this->request->post['config_image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['config_image'], 100, 100); + } elseif (isset($store_info['config_image']) && is_file(DIR_IMAGE . $store_info['config_image'])) { + $data['thumb'] = $this->model_tool_image->resize($store_info['config_image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['config_open'])) { + $data['config_open'] = $this->request->post['config_open']; + } elseif (isset($store_info['config_open'])) { + $data['config_open'] = $store_info['config_open']; + } else { + $data['config_open'] = ''; + } + + if (isset($this->request->post['config_comment'])) { + $data['config_comment'] = $this->request->post['config_comment']; + } elseif (isset($store_info['config_comment'])) { + $data['config_comment'] = $store_info['config_comment']; + } else { + $data['config_comment'] = ''; + } + + $this->load->model('localisation/location'); + + $data['locations'] = $this->model_localisation_location->getLocations(); + + if (isset($this->request->post['config_location'])) { + $data['config_location'] = $this->request->post['config_location']; + } elseif (isset($store_info['config_location'])) { + $data['config_location'] = $this->config->get('config_location'); + } else { + $data['config_location'] = array(); + } + + if (isset($this->request->post['config_country_id'])) { + $data['config_country_id'] = $this->request->post['config_country_id']; + } elseif (isset($store_info['config_country_id'])) { + $data['config_country_id'] = $store_info['config_country_id']; + } else { + $data['config_country_id'] = $this->config->get('config_country_id'); + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + if (isset($this->request->post['config_zone_id'])) { + $data['config_zone_id'] = $this->request->post['config_zone_id']; + } elseif (isset($store_info['config_zone_id'])) { + $data['config_zone_id'] = $store_info['config_zone_id']; + } else { + $data['config_zone_id'] = $this->config->get('config_zone_id'); + } + + if (isset($this->request->post['config_language'])) { + $data['config_language'] = $this->request->post['config_language']; + } elseif (isset($store_info['config_language'])) { + $data['config_language'] = $store_info['config_language']; + } else { + $data['config_language'] = $this->config->get('config_language'); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['config_currency'])) { + $data['config_currency'] = $this->request->post['config_currency']; + } elseif (isset($store_info['config_currency'])) { + $data['config_currency'] = $store_info['config_currency']; + } else { + $data['config_currency'] = $this->config->get('config_currency'); + } + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + if (isset($this->request->post['config_tax'])) { + $data['config_tax'] = $this->request->post['config_tax']; + } elseif (isset($store_info['config_tax'])) { + $data['config_tax'] = $store_info['config_tax']; + } else { + $data['config_tax'] = ''; + } + + if (isset($this->request->post['config_tax_default'])) { + $data['config_tax_default'] = $this->request->post['config_tax_default']; + } elseif (isset($store_info['config_tax_default'])) { + $data['config_tax_default'] = $store_info['config_tax_default']; + } else { + $data['config_tax_default'] = ''; + } + + if (isset($this->request->post['config_tax_customer'])) { + $data['config_tax_customer'] = $this->request->post['config_tax_customer']; + } elseif (isset($store_info['config_tax_customer'])) { + $data['config_tax_customer'] = $store_info['config_tax_customer']; + } else { + $data['config_tax_customer'] = ''; + } + + if (isset($this->request->post['config_customer_group_id'])) { + $data['config_customer_group_id'] = $this->request->post['config_customer_group_id']; + } elseif (isset($store_info['config_customer_group_id'])) { + $data['config_customer_group_id'] = $store_info['config_customer_group_id']; + } else { + $data['config_customer_group_id'] = ''; + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['config_customer_group_display'])) { + $data['config_customer_group_display'] = $this->request->post['config_customer_group_display']; + } elseif (isset($store_info['config_customer_group_display'])) { + $data['config_customer_group_display'] = $store_info['config_customer_group_display']; + } else { + $data['config_customer_group_display'] = array(); + } + + if (isset($this->request->post['config_customer_price'])) { + $data['config_customer_price'] = $this->request->post['config_customer_price']; + } elseif (isset($store_info['config_customer_price'])) { + $data['config_customer_price'] = $store_info['config_customer_price']; + } else { + $data['config_customer_price'] = ''; + } + + if (isset($this->request->post['config_account_id'])) { + $data['config_account_id'] = $this->request->post['config_account_id']; + } elseif (isset($store_info['config_account_id'])) { + $data['config_account_id'] = $store_info['config_account_id']; + } else { + $data['config_account_id'] = ''; + } + + $this->load->model('catalog/information'); + + $data['informations'] = $this->model_catalog_information->getInformations(); + + if (isset($this->request->post['config_cart_weight'])) { + $data['config_cart_weight'] = $this->request->post['config_cart_weight']; + } elseif (isset($store_info['config_cart_weight'])) { + $data['config_cart_weight'] = $store_info['config_cart_weight']; + } else { + $data['config_cart_weight'] = ''; + } + + if (isset($this->request->post['config_checkout_guest'])) { + $data['config_checkout_guest'] = $this->request->post['config_checkout_guest']; + } elseif (isset($store_info['config_checkout_guest'])) { + $data['config_checkout_guest'] = $store_info['config_checkout_guest']; + } else { + $data['config_checkout_guest'] = ''; + } + + if (isset($this->request->post['config_checkout_id'])) { + $data['config_checkout_id'] = $this->request->post['config_checkout_id']; + } elseif (isset($store_info['config_checkout_id'])) { + $data['config_checkout_id'] = $store_info['config_checkout_id']; + } else { + $data['config_checkout_id'] = ''; + } + + if (isset($this->request->post['config_order_status_id'])) { + $data['config_order_status_id'] = $this->request->post['config_order_status_id']; + } elseif (isset($store_info['config_order_status_id'])) { + $data['config_order_status_id'] = $store_info['config_order_status_id']; + } else { + $data['config_order_status_id'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['config_stock_display'])) { + $data['config_stock_display'] = $this->request->post['config_stock_display']; + } elseif (isset($store_info['config_stock_display'])) { + $data['config_stock_display'] = $store_info['config_stock_display']; + } else { + $data['config_stock_display'] = ''; + } + + if (isset($this->request->post['config_stock_checkout'])) { + $data['config_stock_checkout'] = $this->request->post['config_stock_checkout']; + } elseif (isset($store_info['config_stock_checkout'])) { + $data['config_stock_checkout'] = $store_info['config_stock_checkout']; + } else { + $data['config_stock_checkout'] = ''; + } + + if (isset($this->request->post['config_logo'])) { + $data['config_logo'] = $this->request->post['config_logo']; + } elseif (isset($store_info['config_logo'])) { + $data['config_logo'] = $store_info['config_logo']; + } else { + $data['config_logo'] = ''; + } + + if (isset($this->request->post['config_logo']) && is_file(DIR_IMAGE . $this->request->post['config_logo'])) { + $data['logo'] = $this->model_tool_image->resize($this->request->post['config_logo'], 100, 100); + } elseif (isset($store_info['config_logo']) && is_file(DIR_IMAGE . $store_info['config_logo'])) { + $data['logo'] = $this->model_tool_image->resize($store_info['config_logo'], 100, 100); + } else { + $data['logo'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['config_icon'])) { + $data['config_icon'] = $this->request->post['config_icon']; + } elseif (isset($store_info['config_icon'])) { + $data['config_icon'] = $store_info['config_icon']; + } else { + $data['config_icon'] = ''; + } + + if (isset($this->request->post['config_icon']) && is_file(DIR_IMAGE . $this->request->post['config_icon'])) { + $data['icon'] = $this->model_tool_image->resize($this->request->post['config_icon'], 100, 100); + } elseif (isset($store_info['config_icon']) && is_file(DIR_IMAGE . $store_info['config_icon'])) { + $data['icon'] = $this->model_tool_image->resize($store_info['config_icon'], 100, 100); + } else { + $data['icon'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + if (isset($this->request->post['config_secure'])) { + $data['config_secure'] = $this->request->post['config_secure']; + } elseif (isset($store_info['config_secure'])) { + $data['config_secure'] = $store_info['config_secure']; + } else { + $data['config_secure'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('setting/store_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'setting/store')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['config_url']) { + $this->error['url'] = $this->language->get('error_url'); + } + + if (!$this->request->post['config_meta_title']) { + $this->error['meta_title'] = $this->language->get('error_meta_title'); + } + + if (!$this->request->post['config_name']) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['config_owner']) < 3) || (utf8_strlen($this->request->post['config_owner']) > 64)) { + $this->error['owner'] = $this->language->get('error_owner'); + } + + if ((utf8_strlen($this->request->post['config_address']) < 3) || (utf8_strlen($this->request->post['config_address']) > 256)) { + $this->error['address'] = $this->language->get('error_address'); + } + + if ((utf8_strlen($this->request->post['config_email']) > 96) || !filter_var($this->request->post['config_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + if ((utf8_strlen($this->request->post['config_telephone']) < 3) || (utf8_strlen($this->request->post['config_telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + if (!empty($this->request->post['config_customer_group_display']) && !in_array($this->request->post['config_customer_group_id'], $this->request->post['config_customer_group_display'])) { + $this->error['customer_group_display'] = $this->language->get('error_customer_group_display'); + } + + 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', 'setting/store')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $store_id) { + if (!$store_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_sale_order->getTotalOrdersByStoreId($store_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/startup/error.php b/public/admin/controller/startup/error.php new file mode 100644 index 0000000..8489b9c --- /dev/null +++ b/public/admin/controller/startup/error.php @@ -0,0 +1,43 @@ +<?php +class ControllerStartupError extends Controller { + public function index() { + $this->registry->set('log', new Log($this->config->get('config_error_filename') ? $this->config->get('config_error_filename') : $this->config->get('error_filename'))); + + set_error_handler(array($this, 'handler')); + } + + public function handler($code, $message, $file, $line) { + // error suppressed with @ + if (error_reporting() === 0) { + return false; + } + + switch ($code) { + case E_NOTICE: + case E_USER_NOTICE: + $error = 'Notice'; + break; + case E_WARNING: + case E_USER_WARNING: + $error = 'Warning'; + break; + case E_ERROR: + case E_USER_ERROR: + $error = 'Fatal Error'; + break; + default: + $error = 'Unknown'; + break; + } + + if ($this->config->get('config_error_display')) { + echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>'; + } + + if ($this->config->get('config_error_log')) { + $this->log->write('PHP ' . $error . ': ' . $message . ' in ' . $file . ' on line ' . $line); + } + + return true; + } +} diff --git a/public/admin/controller/startup/event.php b/public/admin/controller/startup/event.php new file mode 100644 index 0000000..2aa9604 --- /dev/null +++ b/public/admin/controller/startup/event.php @@ -0,0 +1,15 @@ +<?php +class ControllerStartupEvent extends Controller { + public function index() { + // Add events from the DB + $this->load->model('setting/event'); + + $results = $this->model_setting_event->getEvents(); + + foreach ($results as $result) { + if ((substr($result['trigger'], 0, 6) == 'admin/') && $result['status']) { + $this->event->register(substr($result['trigger'], 6), new Action($result['action']), $result['sort_order']); + } + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/startup/login.php b/public/admin/controller/startup/login.php new file mode 100644 index 0000000..da058cc --- /dev/null +++ b/public/admin/controller/startup/login.php @@ -0,0 +1,38 @@ +<?php +class ControllerStartupLogin extends Controller { + public function index() { + $route = isset($this->request->get['route']) ? $this->request->get['route'] : ''; + + $ignore = array( + 'common/login', + 'common/forgotten', + 'common/reset' + ); + + // User + $this->registry->set('user', new Cart\User($this->registry)); + + if (!$this->user->isLogged() && !in_array($route, $ignore)) { + return new Action('common/login'); + } + + if (isset($this->request->get['route'])) { + $ignore = array( + 'common/login', + 'common/logout', + 'common/forgotten', + 'common/reset', + 'error/not_found', + 'error/permission' + ); + + if (!in_array($route, $ignore) && (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token']))) { + return new Action('common/login'); + } + } else { + if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token'])) { + return new Action('common/login'); + } + } + } +} diff --git a/public/admin/controller/startup/permission.php b/public/admin/controller/startup/permission.php new file mode 100644 index 0000000..e73e504 --- /dev/null +++ b/public/admin/controller/startup/permission.php @@ -0,0 +1,55 @@ +<?php +class ControllerStartupPermission extends Controller { + public function index() { + if (isset($this->request->get['route'])) { + $route = ''; + + $part = explode('/', $this->request->get['route']); + + if (isset($part[0])) { + $route .= $part[0]; + } + + if (isset($part[1])) { + $route .= '/' . $part[1]; + } + + // If a 3rd part is found we need to check if its under one of the extension folders. + $extension = array( + 'extension/advertise', + 'extension/dashboard', + 'extension/analytics', + 'extension/captcha', + 'extension/extension', + 'extension/feed', + 'extension/fraud', + 'extension/module', + 'extension/payment', + 'extension/shipping', + 'extension/theme', + 'extension/total', + 'extension/report', + 'extension/openbay' + ); + + if (isset($part[2]) && in_array($route, $extension)) { + $route .= '/' . $part[2]; + } + + // We want to ingore some pages from having its permission checked. + $ignore = array( + 'common/dashboard', + 'common/login', + 'common/logout', + 'common/forgotten', + 'common/reset', + 'error/not_found', + 'error/permission' + ); + + if (!in_array($route, $ignore) && !$this->user->hasPermission('access', $route)) { + return new Action('error/permission'); + } + } + } +} diff --git a/public/admin/controller/startup/router.php b/public/admin/controller/startup/router.php new file mode 100644 index 0000000..ec8e0ca --- /dev/null +++ b/public/admin/controller/startup/router.php @@ -0,0 +1,37 @@ +<?php +class ControllerStartupRouter extends Controller { + public function index() { + // Route + if (isset($this->request->get['route']) && $this->request->get['route'] != 'startup/router') { + $route = $this->request->get['route']; + } else { + $route = $this->config->get('action_default'); + } + + $data = array(); + + // Sanitize the call + $route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route); + + // Trigger the pre events + $result = $this->event->trigger('controller/' . $route . '/before', array(&$route, &$data)); + + if (!is_null($result)) { + return $result; + } + + $action = new Action($route); + + // Any output needs to be another Action object. + $output = $action->execute($this->registry, $data); + + // Trigger the post events + $result = $this->event->trigger('controller/' . $route . '/after', array(&$route, &$output)); + + if (!is_null($result)) { + return $result; + } + + return $output; + } +} diff --git a/public/admin/controller/startup/sass.php b/public/admin/controller/startup/sass.php new file mode 100644 index 0000000..9af89b3 --- /dev/null +++ b/public/admin/controller/startup/sass.php @@ -0,0 +1,27 @@ +<?php +class ControllerStartupSass extends Controller { + public function index() { + $file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css'; + + if (!is_file($file) || !$this->config->get('developer_sass')) { + include_once(DIR_STORAGE . 'vendor/scss.inc.php'); + + $scss = new Scssc(); + $scss->setImportPaths(DIR_APPLICATION . 'view/stylesheet/sass/'); + + $output = $scss->compile('@import "_bootstrap.scss"'); + + $handle = fopen($file, 'w'); + + flock($handle, LOCK_EX); + + fwrite($handle, $output); + + fflush($handle); + + flock($handle, LOCK_UN); + + fclose($handle); + } + } +} diff --git a/public/admin/controller/startup/startup.php b/public/admin/controller/startup/startup.php new file mode 100644 index 0000000..1e50294 --- /dev/null +++ b/public/admin/controller/startup/startup.php @@ -0,0 +1,64 @@ +<?php +class ControllerStartupStartup extends Controller { + public function index() { + // Settings + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '0'"); + + foreach ($query->rows as $setting) { + if (!$setting['serialized']) { + $this->config->set($setting['key'], $setting['value']); + } else { + $this->config->set($setting['key'], json_decode($setting['value'], true)); + } + } + + // Theme + $this->config->set('template_cache', $this->config->get('developer_theme')); + + // Language + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $this->db->escape($this->config->get('config_admin_language')) . "'"); + + if ($query->num_rows) { + $this->config->set('config_language_id', $query->row['language_id']); + } + + // Language + $language = new Language($this->config->get('config_admin_language')); + $language->load($this->config->get('config_admin_language')); + $this->registry->set('language', $language); + + // Customer + $this->registry->set('customer', new Cart\Customer($this->registry)); + + // Currency + $this->registry->set('currency', new Cart\Currency($this->registry)); + + // Tax + $this->registry->set('tax', new Cart\Tax($this->registry)); + + if ($this->config->get('config_tax_default') == 'shipping') { + $this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id')); + } + + if ($this->config->get('config_tax_default') == 'payment') { + $this->tax->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id')); + } + + $this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id')); + + // Weight + $this->registry->set('weight', new Cart\Weight($this->registry)); + + // Length + $this->registry->set('length', new Cart\Length($this->registry)); + + // Cart + $this->registry->set('cart', new Cart\Cart($this->registry)); + + // Encryption + $this->registry->set('encryption', new Encryption($this->config->get('config_encryption'))); + + // OpenBay Pro + $this->registry->set('openbay', new Openbay($this->registry)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/tool/backup.php b/public/admin/controller/tool/backup.php new file mode 100644 index 0000000..d8354b8 --- /dev/null +++ b/public/admin/controller/tool/backup.php @@ -0,0 +1,160 @@ +<?php +class ControllerToolBackup extends Controller { + public function index() { + $this->load->language('tool/backup'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['export'] = $this->url->link('tool/backup/export', 'user_token=' . $this->session->data['user_token'], true); + + $this->load->model('tool/backup'); + + $data['tables'] = $this->model_tool_backup->getTables(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('tool/backup', $data)); + } + + public function import() { + $this->load->language('tool/backup'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'tool/backup')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (isset($this->request->files['import']['tmp_name']) && is_uploaded_file($this->request->files['import']['tmp_name'])) { + $filename = tempnam(DIR_UPLOAD, 'bac'); + + move_uploaded_file($this->request->files['import']['tmp_name'], $filename); + } elseif (isset($this->request->get['import'])) { + $filename = html_entity_decode($this->request->get['import'], ENT_QUOTES, 'UTF-8'); + } else { + $filename = ''; + } + + if (!is_file($filename)) { + $json['error'] = $this->language->get('error_file'); + } + + if (isset($this->request->get['position'])) { + $position = $this->request->get['position']; + } else { + $position = 0; + } + + if (!$json) { + // We set $i so we can batch execute the queries rather than do them all at once. + $i = 0; + $start = false; + + $handle = fopen($filename, 'r'); + + fseek($handle, $position, SEEK_SET); + + while (!feof($handle) && ($i < 100)) { + $position = ftell($handle); + + $line = fgets($handle, 1000000); + + if (substr($line, 0, 14) == 'TRUNCATE TABLE' || substr($line, 0, 11) == 'INSERT INTO') { + $sql = ''; + + $start = true; + } + + if ($i > 0 && (substr($line, 0, 24) == 'TRUNCATE TABLE `oc_user`' || substr($line, 0, 30) == 'TRUNCATE TABLE `oc_user_group`')) { + fseek($handle, $position, SEEK_SET); + + break; + } + + if ($start) { + $sql .= $line; + } + + if ($start && substr($line, -2) == ";\n") { + $this->db->query(substr($sql, 0, strlen($sql) -2)); + + $start = false; + } + + $i++; + } + + $position = ftell($handle); + + $size = filesize($filename); + + $json['total'] = round(($position / $size) * 100); + + if ($position && !feof($handle)) { + $json['next'] = str_replace('&', '&', $this->url->link('tool/backup/import', 'user_token=' . $this->session->data['user_token'] . '&import=' . $filename . '&position=' . $position, true)); + + fclose($handle); + } else { + fclose($handle); + + unlink($filename); + + $json['success'] = $this->language->get('text_success'); + + $this->cache->delete('*'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function export() { + $this->load->language('tool/backup'); + + if (!isset($this->request->post['backup'])) { + $this->session->data['error'] = $this->language->get('error_export'); + + $this->response->redirect($this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token'], true)); + } elseif (!$this->user->hasPermission('modify', 'tool/backup')) { + $this->session->data['error'] = $this->language->get('error_permission'); + + $this->response->redirect($this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->response->addheader('Pragma: public'); + $this->response->addheader('Expires: 0'); + $this->response->addheader('Content-Description: File Transfer'); + $this->response->addheader('Content-Type: application/octet-stream'); + $this->response->addheader('Content-Disposition: attachment; filename="' . DB_DATABASE . '_' . date('Y-m-d_H-i-s', time()) . '_backup.sql"'); + $this->response->addheader('Content-Transfer-Encoding: binary'); + + $this->load->model('tool/backup'); + + $this->response->setOutput($this->model_tool_backup->backup($this->request->post['backup'])); + } + } +} diff --git a/public/admin/controller/tool/log.php b/public/admin/controller/tool/log.php new file mode 100644 index 0000000..389b95a --- /dev/null +++ b/public/admin/controller/tool/log.php @@ -0,0 +1,121 @@ +<?php +class ControllerToolLog extends Controller { + private $error = array(); + + public function index() { + $this->load->language('tool/log'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + + unset($this->session->data['error']); + } elseif (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'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['download'] = $this->url->link('tool/log/download', 'user_token=' . $this->session->data['user_token'], true); + $data['clear'] = $this->url->link('tool/log/clear', 'user_token=' . $this->session->data['user_token'], true); + + $data['log'] = ''; + + $file = DIR_LOGS . $this->config->get('config_error_filename'); + + if (file_exists($file)) { + $size = filesize($file); + + if ($size >= 5242880) { + $suffix = array( + 'B', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ); + + $i = 0; + + while (($size / 1024) > 1) { + $size = $size / 1024; + $i++; + } + + $data['error_warning'] = sprintf($this->language->get('error_warning'), basename($file), round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]); + } else { + $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null); + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('tool/log', $data)); + } + + public function download() { + $this->load->language('tool/log'); + + $file = DIR_LOGS . $this->config->get('config_error_filename'); + + if (file_exists($file) && filesize($file) > 0) { + $this->response->addheader('Pragma: public'); + $this->response->addheader('Expires: 0'); + $this->response->addheader('Content-Description: File Transfer'); + $this->response->addheader('Content-Type: application/octet-stream'); + $this->response->addheader('Content-Disposition: attachment; filename="' . $this->config->get('config_name') . '_' . date('Y-m-d_H-i-s', time()) . '_error.log"'); + $this->response->addheader('Content-Transfer-Encoding: binary'); + + $this->response->setOutput(file_get_contents($file, FILE_USE_INCLUDE_PATH, null)); + } else { + $this->session->data['error'] = sprintf($this->language->get('error_warning'), basename($file), '0B'); + + $this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function clear() { + $this->load->language('tool/log'); + + if (!$this->user->hasPermission('modify', 'tool/log')) { + $this->session->data['error'] = $this->language->get('error_permission'); + } else { + $file = DIR_LOGS . $this->config->get('config_error_filename'); + + $handle = fopen($file, 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/tool/upload.php b/public/admin/controller/tool/upload.php new file mode 100644 index 0000000..9d5219d --- /dev/null +++ b/public/admin/controller/tool/upload.php @@ -0,0 +1,391 @@ +<?php +class ControllerToolUpload extends Controller { + private $error = array(); + + public function index() { + $this->load->language('tool/upload'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('tool/upload'); + + $this->getList(); + } + + public function delete() { + $this->load->language('tool/upload'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('tool/upload'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $upload_id) { + // Remove file before deleting DB record. + $upload_info = $this->model_tool_upload->getUpload($upload_id); + + if ($upload_info && is_file(DIR_UPLOAD . $upload_info['filename'])) { + unlink(DIR_UPLOAD . $upload_info['filename']); + } + + $this->model_tool_upload->deleteUpload($upload_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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('tool/upload', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'date_added'; + } + + 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_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['delete'] = $this->url->link('tool/upload/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['uploads'] = array(); + + $filter_data = array( + 'filter_name' => $filter_name, + 'filter_date_added' => $filter_date_added, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $upload_total = $this->model_tool_upload->getTotalUploads($filter_data); + + $results = $this->model_tool_upload->getUploads($filter_data); + + foreach ($results as $result) { + $data['uploads'][] = array( + 'upload_id' => $result['upload_id'], + 'name' => $result['name'], + 'filename' => $result['filename'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'download' => $this->url->link('tool/upload/download', 'user_token=' . $this->session->data['user_token'] . '&code=' . $result['code'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_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_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_filename'] = $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'] . '&sort=filename' . $url, true); + $data['sort_date_added'] = $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + 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 = $upload_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($upload_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($upload_total - $this->config->get('config_limit_admin'))) ? $upload_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $upload_total, ceil($upload_total / $this->config->get('config_limit_admin'))); + + $data['filter_name'] = $filter_name; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('tool/upload', $data)); + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'tool/upload')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function download() { + $this->load->model('tool/upload'); + + if (isset($this->request->get['code'])) { + $code = $this->request->get['code']; + } else { + $code = 0; + } + + $upload_info = $this->model_tool_upload->getUploadByCode($code); + + if ($upload_info) { + $file = DIR_UPLOAD . $upload_info['filename']; + $mask = basename($upload_info['name']); + + 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['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('error/not_found', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('error/not_found', $data)); + } + } + + public function upload() { + $this->load->language('sale/order'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'tool/upload')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_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_ext_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'); + } + + // Check to see if any PHP files are trying to be uploaded + $content = file_get_contents($this->request->files['file']['tmp_name']); + + if (preg_match('/\<\?php/i', $content)) { + $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 . '.' . token(32); + + move_uploaded_file($this->request->files['file']['tmp_name'], DIR_UPLOAD . $file); + + // Hide the uploaded file name so people can not link to it directly. + $this->load->model('tool/upload'); + + $json['code'] = $this->model_tool_upload->addUpload($filename, $file); + + $json['success'] = $this->language->get('text_upload'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/user/api.php b/public/admin/controller/user/api.php new file mode 100644 index 0000000..c07c628 --- /dev/null +++ b/public/admin/controller/user/api.php @@ -0,0 +1,417 @@ +<?php +class ControllerUserApi extends Controller { + private $error = array(); + + public function index() { + $this->load->language('user/api'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/api'); + + $this->getList(); + } + + public function add() { + $this->load->language('user/api'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/api'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_api->addApi($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('user/api'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/api'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_api->editApi($this->request->get['api_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('user/api'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/api'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $api_id) { + $this->model_user_api->deleteApi($api_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'username'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('user/api/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('user/api/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['apis'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $user_total = $this->model_user_api->getTotalApis(); + + $results = $this->model_user_api->getApis($filter_data); + + foreach ($results as $result) { + $data['apis'][] = array( + 'api_id' => $result['api_id'], + 'username' => $result['username'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + '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'])), + 'edit' => $this->url->link('user/api/edit', 'user_token=' . $this->session->data['user_token'] . '&api_id=' . $result['api_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_username'] = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . '&sort=username' . $url, true); + $data['sort_status'] = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url, true); + + $url = ''; + + 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 = $user_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($user_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($user_total - $this->config->get('config_limit_admin'))) ? $user_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $user_total, ceil($user_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/api_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['api_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + $data['text_ip'] = sprintf($this->language->get('text_ip'), $this->request->server['REMOTE_ADDR']); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['api_id'])) { + $data['action'] = $this->url->link('user/api/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('user/api/edit', 'user_token=' . $this->session->data['user_token'] . '&api_id=' . $this->request->get['api_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['api_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $api_info = $this->model_user_api->getApi($this->request->get['api_id']); + } + + if (isset($this->request->post['username'])) { + $data['username'] = $this->request->post['username']; + } elseif (!empty($api_info)) { + $data['username'] = $api_info['username']; + } else { + $data['username'] = ''; + } + + if (isset($this->request->post['key'])) { + $data['key'] = $this->request->post['key']; + } elseif (!empty($api_info)) { + $data['key'] = $api_info['key']; + } else { + $data['key'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($api_info)) { + $data['status'] = $api_info['status']; + } else { + $data['status'] = 0; + } + + // IP + if (isset($this->request->post['api_ip'])) { + $data['api_ips'] = $this->request->post['api_ip']; + } elseif (isset($this->request->get['api_id'])) { + $data['api_ips'] = $this->model_user_api->getApiIps($this->request->get['api_id']); + } else { + $data['api_ips'] = array(); + } + + // Session + $data['api_sessions'] = array(); + + if (isset($this->request->get['api_id'])) { + $results = $this->model_user_api->getApiSessions($this->request->get['api_id']); + + foreach ($results as $result) { + $data['api_sessions'][] = array( + 'api_session_id' => $result['api_session_id'], + 'session_id' => $result['session_id'], + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), + 'date_modified' => date($this->language->get('datetime_format'), strtotime($result['date_modified'])) + ); + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/api_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'user/user')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen(trim($this->request->post['username'])) < 3) || (utf8_strlen(trim($this->request->post['username'])) > 64)) { + $this->error['username'] = $this->language->get('error_username'); + } + + if ((utf8_strlen($this->request->post['key']) < 64) || (utf8_strlen($this->request->post['key']) > 256)) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!isset($this->error['warning']) && !isset($this->request->post['api_ip'])) { + $this->error['warning'] = $this->language->get('error_ip'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'user/api')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function deleteSession() { + $this->load->language('user/api'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'user/api')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('user/api'); + + $this->model_user_api->deleteApiSession($this->request->get['api_session_id']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/user/user.php b/public/admin/controller/user/user.php new file mode 100644 index 0000000..7bf4c61 --- /dev/null +++ b/public/admin/controller/user/user.php @@ -0,0 +1,495 @@ +<?php +class ControllerUserUser extends Controller { + private $error = array(); + + public function index() { + $this->load->language('user/user'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + $this->getList(); + } + + public function add() { + $this->load->language('user/user'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_user->addUser($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('user/user'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_user->editUser($this->request->get['user_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('user/user'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $user_id) { + $this->model_user_user->deleteUser($user_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'username'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('user/user/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('user/user/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['users'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $user_total = $this->model_user_user->getTotalUsers(); + + $results = $this->model_user_user->getUsers($filter_data); + + foreach ($results as $result) { + $data['users'][] = array( + 'user_id' => $result['user_id'], + 'username' => $result['username'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('user/user/edit', 'user_token=' . $this->session->data['user_token'] . '&user_id=' . $result['user_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_username'] = $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . '&sort=username' . $url, true); + $data['sort_status'] = $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url, true); + + $url = ''; + + 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 = $user_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($user_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($user_total - $this->config->get('config_limit_admin'))) ? $user_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $user_total, ceil($user_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/user_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['user_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['confirm'])) { + $data['error_confirm'] = $this->error['confirm']; + } else { + $data['error_confirm'] = ''; + } + + 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'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['user_id'])) { + $data['action'] = $this->url->link('user/user/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('user/user/edit', 'user_token=' . $this->session->data['user_token'] . '&user_id=' . $this->request->get['user_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['user_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $user_info = $this->model_user_user->getUser($this->request->get['user_id']); + } + + if (isset($this->request->post['username'])) { + $data['username'] = $this->request->post['username']; + } elseif (!empty($user_info)) { + $data['username'] = $user_info['username']; + } else { + $data['username'] = ''; + } + + if (isset($this->request->post['user_group_id'])) { + $data['user_group_id'] = $this->request->post['user_group_id']; + } elseif (!empty($user_info)) { + $data['user_group_id'] = $user_info['user_group_id']; + } else { + $data['user_group_id'] = ''; + } + + $this->load->model('user/user_group'); + + $data['user_groups'] = $this->model_user_user_group->getUserGroups(); + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->post['confirm'])) { + $data['confirm'] = $this->request->post['confirm']; + } else { + $data['confirm'] = ''; + } + + if (isset($this->request->post['firstname'])) { + $data['firstname'] = $this->request->post['firstname']; + } elseif (!empty($user_info)) { + $data['firstname'] = $user_info['firstname']; + } else { + $data['firstname'] = ''; + } + + if (isset($this->request->post['lastname'])) { + $data['lastname'] = $this->request->post['lastname']; + } elseif (!empty($user_info)) { + $data['lastname'] = $user_info['lastname']; + } else { + $data['lastname'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } elseif (!empty($user_info)) { + $data['email'] = $user_info['email']; + } else { + $data['email'] = ''; + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($user_info)) { + $data['image'] = $user_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($user_info) && $user_info['image'] && is_file(DIR_IMAGE . $user_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($user_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($user_info)) { + $data['status'] = $user_info['status']; + } else { + $data['status'] = 0; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/user_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'user/user')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['username']) < 3) || (utf8_strlen($this->request->post['username']) > 20)) { + $this->error['username'] = $this->language->get('error_username'); + } + + $user_info = $this->model_user_user->getUserByUsername($this->request->post['username']); + + if (!isset($this->request->get['user_id'])) { + if ($user_info) { + $this->error['warning'] = $this->language->get('error_exists_username'); + } + } else { + if ($user_info && ($this->request->get['user_id'] != $user_info['user_id'])) { + $this->error['warning'] = $this->language->get('error_exists_username'); + } + } + + 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) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + $user_info = $this->model_user_user->getUserByEmail($this->request->post['email']); + + if (!isset($this->request->get['user_id'])) { + if ($user_info) { + $this->error['warning'] = $this->language->get('error_exists_email'); + } + } else { + if ($user_info && ($this->request->get['user_id'] != $user_info['user_id'])) { + $this->error['warning'] = $this->language->get('error_exists_email'); + } + } + + if ($this->request->post['password'] || (!isset($this->request->get['user_id']))) { + if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { + $this->error['password'] = $this->language->get('error_password'); + } + + if ($this->request->post['password'] != $this->request->post['confirm']) { + $this->error['confirm'] = $this->language->get('error_confirm'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'user/user')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['selected'] as $user_id) { + if ($this->user->getId() == $user_id) { + $this->error['warning'] = $this->language->get('error_account'); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/user/user_permission.php b/public/admin/controller/user/user_permission.php new file mode 100644 index 0000000..d13dc57 --- /dev/null +++ b/public/admin/controller/user/user_permission.php @@ -0,0 +1,409 @@ +<?php +class ControllerUserUserPermission extends Controller { + private $error = array(); + + public function index() { + $this->load->language('user/user_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user_group'); + + $this->getList(); + } + + public function add() { + $this->load->language('user/user_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_user_group->addUserGroup($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('user/user_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user_group'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_user_user_group->editUserGroup($this->request->get['user_group_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('user/user_group'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('user/user_group'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $user_group_id) { + $this->model_user_user_group->deleteUserGroup($user_group_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + 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('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('user/user_permission/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('user/user_permission/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_groups'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $user_group_total = $this->model_user_user_group->getTotalUserGroups(); + + $results = $this->model_user_user_group->getUserGroups($filter_data); + + foreach ($results as $result) { + $data['user_groups'][] = array( + 'user_group_id' => $result['user_group_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('user/user_permission/edit', 'user_token=' . $this->session->data['user_token'] . '&user_group_id=' . $result['user_group_id'] . $url, true) + ); + } + + 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 ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + 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 = $user_group_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($user_group_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($user_group_total - $this->config->get('config_limit_admin'))) ? $user_group_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $user_group_total, ceil($user_group_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/user_group_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['user_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + 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', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['user_group_id'])) { + $data['action'] = $this->url->link('user/user_permission/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('user/user_permission/edit', 'user_token=' . $this->session->data['user_token'] . '&user_group_id=' . $this->request->get['user_group_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['user_group_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') { + $user_group_info = $this->model_user_user_group->getUserGroup($this->request->get['user_group_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($user_group_info)) { + $data['name'] = $user_group_info['name']; + } else { + $data['name'] = ''; + } + + $ignore = array( + 'common/dashboard', + 'common/startup', + 'common/login', + 'common/logout', + 'common/forgotten', + 'common/reset', + 'common/footer', + 'common/header', + 'error/not_found', + 'error/permission' + ); + + $data['permissions'] = array(); + + $files = array(); + + // Make path into an array + $path = array(DIR_APPLICATION . 'controller/*'); + + // While the path array is still populated keep looping through + while (count($path) != 0) { + $next = array_shift($path); + + foreach (glob($next) as $file) { + // If directory add to path array + if (is_dir($file)) { + $path[] = $file . '/*'; + } + + // Add the file to the files to be deleted array + if (is_file($file)) { + $files[] = $file; + } + } + } + + // Sort the file array + sort($files); + + foreach ($files as $file) { + $controller = substr($file, strlen(DIR_APPLICATION . 'controller/')); + + $permission = substr($controller, 0, strrpos($controller, '.')); + + if (!in_array($permission, $ignore)) { + $data['permissions'][] = $permission; + } + } + + if (isset($this->request->post['permission']['access'])) { + $data['access'] = $this->request->post['permission']['access']; + } elseif (isset($user_group_info['permission']['access'])) { + $data['access'] = $user_group_info['permission']['access']; + } else { + $data['access'] = array(); + } + + if (isset($this->request->post['permission']['modify'])) { + $data['modify'] = $this->request->post['permission']['modify']; + } elseif (isset($user_group_info['permission']['modify'])) { + $data['modify'] = $user_group_info['permission']['modify']; + } else { + $data['modify'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('user/user_group_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'user/user_permission')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'user/user_permission')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('user/user'); + + foreach ($this->request->post['selected'] as $user_group_id) { + $user_total = $this->model_user_user->getTotalUsersByGroupId($user_group_id); + + if ($user_total) { + $this->error['warning'] = sprintf($this->language->get('error_user'), $user_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file |