aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/controller/marketplace
diff options
context:
space:
mode:
Diffstat (limited to 'public/admin/controller/marketplace')
-rw-r--r--public/admin/controller/marketplace/api.php39
-rw-r--r--public/admin/controller/marketplace/event.php260
-rw-r--r--public/admin/controller/marketplace/extension.php57
-rw-r--r--public/admin/controller/marketplace/install.php520
-rw-r--r--public/admin/controller/marketplace/installer.php172
-rw-r--r--public/admin/controller/marketplace/marketplace.php1111
-rw-r--r--public/admin/controller/marketplace/modification.php777
-rw-r--r--public/admin/controller/marketplace/openbay.php2303
8 files changed, 5239 insertions, 0 deletions
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('&amp;', '&', $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('&amp;', '&', $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('&amp;', '&', $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('&amp;', '&', $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('&amp;', '&', $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('&amp;', '&', $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));
+ }
+}